Skip to content

Commit

Permalink
[*] style: Fix some spelling issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew-M-C committed Sep 28, 2024
1 parent ec17a88 commit ff80771
Show file tree
Hide file tree
Showing 21 changed files with 122 additions and 124 deletions.
6 changes: 3 additions & 3 deletions conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func escapeStringToBuff(s string, buf buffer.Buffer, opt *Opt) {
}
}

func intfToInt(v any) (u int, err error) {
func anyToInt(v any) (u int, err error) {
switch v := v.(type) {
case int:
u = v
Expand Down Expand Up @@ -162,7 +162,7 @@ func intfToInt(v any) (u int, err error) {
return
}

// func intfToInt64(v any) (i int64, err error) {
// func anyToInt64(v any) (i int64, err error) {
// switch v.(type) {
// case int:
// i = int64(v.(int))
Expand Down Expand Up @@ -191,7 +191,7 @@ func intfToInt(v any) (u int, err error) {
// return
// }

func intfToString(v any) (s string, err error) {
func anyToString(v any) (s string, err error) {
if v == nil {
return "", fmt.Errorf("%w: parameter is nil", ErrParameterError)
}
Expand Down
18 changes: 9 additions & 9 deletions errors.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package jsonvalue

// Error is equavilent to string and used to create some error constants in this package.
// Error is equivalent to string and used to create some error constants in this package.
// Error constants: http://godoc.org/github.com/Andrew-M-C/go.jsonvalue/#pkg-constants
type Error string

Expand All @@ -9,7 +9,7 @@ func (e Error) Error() string {
}

const (
// ErrNilParameter identifies input paremeter is nil
// ErrNilParameter identifies input parameter is nil
//
// ErrNilParameter 表示参数为空
ErrNilParameter = Error("nil parameter")
Expand All @@ -19,10 +19,10 @@ const (
// ErrValueUninitialized 表示当前的 jsonvalue 实例未初始化
ErrValueUninitialized = Error("jsonvalue instance is not initialized")

// ErrRawBytesUnrecignized identifies all unexpected raw bytes
// ErrRawBytesUnrecognized identifies all unexpected raw bytes
//
// ErrRawBytesUnrecignized 表示无法识别的序列文本
ErrRawBytesUnrecignized = Error("unrecognized raw text")
// ErrRawBytesUnrecognized 表示无法识别的序列文本
ErrRawBytesUnrecognized = Error("unrecognized raw text")

// ErrNotValidNumberValue shows that a value starts with number or '-' is not eventually a number value
//
Expand All @@ -34,10 +34,10 @@ const (
// ErrNotValidBoolValue 表示当前值不是一个合法的布尔值
ErrNotValidBoolValue = Error("not a valid bool value")

// ErrNotValidNulllValue shows that a value starts with 'n' is not eventually a bool value
// ErrNotValidNullValue shows that a value starts with 'n' is not eventually a bool value
//
// ErrNotValidNulllValue 表示当前不是一个 null 值类型的 JSON
ErrNotValidNulllValue = Error("not a valid null value")
// ErrNotValidNullValue 表示当前不是一个 null 值类型的 JSON
ErrNotValidNullValue = Error("not a valid null value")

// ErrOutOfRange identifies that given position for a JSON array is out of range
//
Expand All @@ -64,7 +64,7 @@ const (
// ErrNotArrayValue 表示当前不是一个数组类型 JSON
ErrNotArrayValue = Error("not an array typed value")

// ErrNotObjectValue shows that operation target value is not an valie object
// ErrNotObjectValue shows that operation target value is not an valid object
//
// ErrNotObjectValue 表示当前不是一个合法的对象类型 JSON
ErrNotObjectValue = Error("not an object typed value")
Expand Down
74 changes: 37 additions & 37 deletions get.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func get(v *V, caseless bool, firstParam any, otherParams ...any) (*V, error) {
}
return get(v, caseless, p1, p2...)
}
child, err := getInCurrValue(v, caseless, firstParam)
child, err := getInCurrentValue(v, caseless, firstParam)
if err != nil {
return &V{}, err
}
Expand Down Expand Up @@ -95,10 +95,10 @@ func getFromObjectChildren(v *V, caseless bool, key string) (child *V, exist boo
return &V{}, false
}

func getInCurrValue(v *V, caseless bool, param any) (*V, error) {
func getInCurrentValue(v *V, caseless bool, param any) (*V, error) {
if v.valueType == Array {
// integer expected
pos, err := intfToInt(param)
pos, err := anyToInt(param)
if err != nil {
return &V{}, err
}
Expand All @@ -110,7 +110,7 @@ func getInCurrValue(v *V, caseless bool, param any) (*V, error) {

} else if v.valueType == Object {
// string expected
key, err := intfToString(param)
key, err := anyToString(param)
if err != nil {
return &V{}, err
}
Expand Down Expand Up @@ -147,7 +147,7 @@ func getBytes(v *V, caseless bool, firstParam any, otherParams ...any) ([]byte,
return b, nil
}

// GetString is equalivent to v, err := Get(...); v.String(). If error occurs, returns "".
// GetString is equivalent to v, err := Get(...); v.String(). If error occurs, returns "".
//
// GetString 等效于 v, err := Get(...); v.String()。如果发生错误,则返回 ""。
func (v *V) GetString(firstParam any, otherParams ...any) (string, error) {
Expand All @@ -165,7 +165,7 @@ func getString(v *V, caseless bool, firstParam any, otherParams ...any) (string,
return ret.String(), nil
}

// GetInt is equalivent to v, err := Get(...); v.Int(). If error occurs, returns 0.
// GetInt is equivalent to v, err := Get(...); v.Int(). If error occurs, returns 0.
//
// GetInt 等效于 v, err := Get(...); v.Int()。如果发生错误,则返回 0。
func (v *V) GetInt(firstParam any, otherParams ...any) (int, error) {
Expand All @@ -181,7 +181,7 @@ func getInt(v *V, caseless bool, firstParam any, otherParams ...any) (int, error
return ret.Int(), err
}

// GetUint is equalivent to v, err := Get(...); v.Uint(). If error occurs, returns 0.
// GetUint is equivalent to v, err := Get(...); v.Uint(). If error occurs, returns 0.
//
// GetUint 等效于 v, err := Get(...); v.Uint()。如果发生错误,则返回 0。
func (v *V) GetUint(firstParam any, otherParams ...any) (uint, error) {
Expand All @@ -197,7 +197,7 @@ func getUint(v *V, caseless bool, firstParam any, otherParams ...any) (uint, err
return ret.Uint(), err
}

// GetInt64 is equalivent to v, err := Get(...); v.Int64(). If error occurs, returns 0.
// GetInt64 is equivalent to v, err := Get(...); v.Int64(). If error occurs, returns 0.
//
// GetInt64 等效于 v, err := Get(...); v.Int64()。如果发生错误,则返回 0。
func (v *V) GetInt64(firstParam any, otherParams ...any) (int64, error) {
Expand All @@ -213,7 +213,7 @@ func getInt64(v *V, caseless bool, firstParam any, otherParams ...any) (int64, e
return ret.Int64(), err
}

// GetUint64 is equalivent to v, err := Get(...); v.Unt64(). If error occurs, returns 0.
// GetUint64 is equivalent to v, err := Get(...); v.Unt64(). If error occurs, returns 0.
//
// GetUint64 等效于 v, err := Get(...); v.Unt64()。如果发生错误,则返回 0。
func (v *V) GetUint64(firstParam any, otherParams ...any) (uint64, error) {
Expand All @@ -229,7 +229,7 @@ func getUint64(v *V, caseless bool, firstParam any, otherParams ...any) (uint64,
return ret.Uint64(), err
}

// GetInt32 is equalivent to v, err := Get(...); v.Int32(). If error occurs, returns 0.
// GetInt32 is equivalent to v, err := Get(...); v.Int32(). If error occurs, returns 0.
//
// GetInt32 等效于 v, err := Get(...); v.Int32()。如果发生错误,则返回 0。
func (v *V) GetInt32(firstParam any, otherParams ...any) (int32, error) {
Expand All @@ -245,7 +245,7 @@ func getInt32(v *V, caseless bool, firstParam any, otherParams ...any) (int32, e
return ret.Int32(), err
}

// GetUint32 is equalivent to v, err := Get(...); v.Uint32(). If error occurs, returns 0.
// GetUint32 is equivalent to v, err := Get(...); v.Uint32(). If error occurs, returns 0.
//
// GetUint32 等效于 v, err := Get(...); v.Uint32()。如果发生错误,则返回 0。
func (v *V) GetUint32(firstParam any, otherParams ...any) (uint32, error) {
Expand All @@ -261,7 +261,7 @@ func getUint32(v *V, caseless bool, firstParam any, otherParams ...any) (uint32,
return ret.Uint32(), err
}

// GetFloat64 is equalivent to v, err := Get(...); v.Float64(). If error occurs, returns 0.0.
// GetFloat64 is equivalent to v, err := Get(...); v.Float64(). If error occurs, returns 0.0.
//
// GetFloat64 等效于 v, err := Get(...); v.Float64()。如果发生错误,则返回 0.0。
func (v *V) GetFloat64(firstParam any, otherParams ...any) (float64, error) {
Expand All @@ -277,7 +277,7 @@ func getFloat64(v *V, caseless bool, firstParam any, otherParams ...any) (float6
return ret.Float64(), err
}

// GetFloat32 is equalivent to v, err := Get(...); v.Float32(). If error occurs, returns 0.0.
// GetFloat32 is equivalent to v, err := Get(...); v.Float32(). If error occurs, returns 0.0.
//
// GetFloat32 等效于 v, err := Get(...); v.Float32()。如果发生错误,则返回 0.0。
func (v *V) GetFloat32(firstParam any, otherParams ...any) (float32, error) {
Expand All @@ -293,7 +293,7 @@ func getFloat32(v *V, caseless bool, firstParam any, otherParams ...any) (float3
return ret.Float32(), err
}

// GetBool is equalivent to v, err := Get(...); v.Bool(). If error occurs, returns false.
// GetBool is equivalent to v, err := Get(...); v.Bool(). If error occurs, returns false.
//
// GetBool 等效于 v, err := Get(...); v.Bool()。如果发生错误,则返回 false。
func (v *V) GetBool(firstParam any, otherParams ...any) (bool, error) {
Expand All @@ -309,7 +309,7 @@ func getBool(v *V, caseless bool, firstParam any, otherParams ...any) (bool, err
return ret.Bool(), err
}

// GetNull is equalivent to v, err := Get(...); raise err if error occurs or v.IsNull() == false.
// GetNull is equivalent to v, err := Get(...); raise err if error occurs or v.IsNull() == false.
//
// GetNull 等效于 v, err := Get(...);,如果发生错误或者 v.IsNull() == false 则返回错误。
func (v *V) GetNull(firstParam any, otherParams ...any) error {
Expand All @@ -327,7 +327,7 @@ func getNull(v *V, caseless bool, firstParam any, otherParams ...any) error {
return nil
}

// GetObject is equalivent to v, err := Get(...); raise err if error occurs or v.IsObject() == false.
// GetObject is equivalent to v, err := Get(...); raise err if error occurs or v.IsObject() == false.
//
// GetObject 等效于 v, err := Get(...);,如果发生错误或者 v.IsObject() == false 则返回错误。
func (v *V) GetObject(firstParam any, otherParams ...any) (*V, error) {
Expand All @@ -345,7 +345,7 @@ func getObject(v *V, caseless bool, firstParam any, otherParams ...any) (*V, err
return ret, nil
}

// GetArray is equalivent to v, err := Get(...); raise err if or v.IsArray() == false.
// GetArray is equivalent to v, err := Get(...); raise err if or v.IsArray() == false.
//
// GetArray 等效于 v, err := Get(...);,如果发生错误或者 v.IsArray() == false 则返回错误。
func (v *V) GetArray(firstParam any, otherParams ...any) (*V, error) {
Expand Down Expand Up @@ -407,86 +407,86 @@ func (v *V) Caseless() Caseless {
return v

case Array, Object:
return &caselessOper{
return &caselessOp{
v: v,
}
}
}

type caselessOper struct {
type caselessOp struct {
v *V
}

func (g *caselessOper) Get(firstParam any, otherParams ...any) (*V, error) {
func (g *caselessOp) Get(firstParam any, otherParams ...any) (*V, error) {
return get(g.v, true, firstParam, otherParams...)
}

func (g *caselessOper) MustGet(firstParam any, otherParams ...any) *V {
func (g *caselessOp) MustGet(firstParam any, otherParams ...any) *V {
res, _ := get(g.v, true, firstParam, otherParams...)
return res
}

func (g *caselessOper) GetBytes(firstParam any, otherParams ...any) ([]byte, error) {
func (g *caselessOp) GetBytes(firstParam any, otherParams ...any) ([]byte, error) {
return getBytes(g.v, true, firstParam, otherParams...)
}

func (g *caselessOper) GetString(firstParam any, otherParams ...any) (string, error) {
func (g *caselessOp) GetString(firstParam any, otherParams ...any) (string, error) {
return getString(g.v, true, firstParam, otherParams...)
}

func (g *caselessOper) GetInt(firstParam any, otherParams ...any) (int, error) {
func (g *caselessOp) GetInt(firstParam any, otherParams ...any) (int, error) {
return getInt(g.v, true, firstParam, otherParams...)
}

func (g *caselessOper) GetUint(firstParam any, otherParams ...any) (uint, error) {
func (g *caselessOp) GetUint(firstParam any, otherParams ...any) (uint, error) {
return getUint(g.v, true, firstParam, otherParams...)
}

func (g *caselessOper) GetInt64(firstParam any, otherParams ...any) (int64, error) {
func (g *caselessOp) GetInt64(firstParam any, otherParams ...any) (int64, error) {
return getInt64(g.v, true, firstParam, otherParams...)
}

func (g *caselessOper) GetUint64(firstParam any, otherParams ...any) (uint64, error) {
func (g *caselessOp) GetUint64(firstParam any, otherParams ...any) (uint64, error) {
return getUint64(g.v, true, firstParam, otherParams...)
}

func (g *caselessOper) GetInt32(firstParam any, otherParams ...any) (int32, error) {
func (g *caselessOp) GetInt32(firstParam any, otherParams ...any) (int32, error) {
return getInt32(g.v, true, firstParam, otherParams...)
}

func (g *caselessOper) GetUint32(firstParam any, otherParams ...any) (uint32, error) {
func (g *caselessOp) GetUint32(firstParam any, otherParams ...any) (uint32, error) {
return getUint32(g.v, true, firstParam, otherParams...)
}

func (g *caselessOper) GetFloat64(firstParam any, otherParams ...any) (float64, error) {
func (g *caselessOp) GetFloat64(firstParam any, otherParams ...any) (float64, error) {
return getFloat64(g.v, true, firstParam, otherParams...)
}

func (g *caselessOper) GetFloat32(firstParam any, otherParams ...any) (float32, error) {
func (g *caselessOp) GetFloat32(firstParam any, otherParams ...any) (float32, error) {
return getFloat32(g.v, true, firstParam, otherParams...)
}

func (g *caselessOper) GetBool(firstParam any, otherParams ...any) (bool, error) {
func (g *caselessOp) GetBool(firstParam any, otherParams ...any) (bool, error) {
return getBool(g.v, true, firstParam, otherParams...)
}

func (g *caselessOper) GetNull(firstParam any, otherParams ...any) error {
func (g *caselessOp) GetNull(firstParam any, otherParams ...any) error {
return getNull(g.v, true, firstParam, otherParams...)
}

func (g *caselessOper) GetObject(firstParam any, otherParams ...any) (*V, error) {
func (g *caselessOp) GetObject(firstParam any, otherParams ...any) (*V, error) {
return getObject(g.v, true, firstParam, otherParams...)
}

func (g *caselessOper) GetArray(firstParam any, otherParams ...any) (*V, error) {
func (g *caselessOp) GetArray(firstParam any, otherParams ...any) (*V, error) {
return getArray(g.v, true, firstParam, otherParams...)
}

func (g *caselessOper) Delete(firstParam any, otherParams ...any) error {
func (g *caselessOp) Delete(firstParam any, otherParams ...any) error {
return g.v.delete(true, firstParam, otherParams...)
}

func (g *caselessOper) MustDelete(firstParam any, otherParams ...any) {
func (g *caselessOp) MustDelete(firstParam any, otherParams ...any) {
_ = g.v.delete(true, firstParam, otherParams...)
}

Expand Down
6 changes: 3 additions & 3 deletions get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ func testCaselessGet(t *testing.T) {

func testNotExistGet(*testing.T) {
cv("unmarshal a not exist V", func() {
v := MustUnmarshalString("blahblah")
v := MustUnmarshalString("blah-blah")
so(v, notNil)
so(v.ValueType(), eq, NotExist)

Expand All @@ -436,14 +436,14 @@ func testNotExistGet(*testing.T) {
})

cv("not-exist-V.GetArray", func() {
v, err := MustUnmarshalString("blahblah").GetArray("some_array", 1, 2, 3)
v, err := MustUnmarshalString("blah-blah").GetArray("some_array", 1, 2, 3)
so(v, notNil)
so(err, isErr)
so(v.ValueType(), eq, NotExist)
})

cv("not-exist-V.GetObject", func() {
v, err := MustUnmarshalString("blahblah").GetArray("some_object", 1, 2, 3)
v, err := MustUnmarshalString("blah-blah").GetArray("some_object", 1, 2, 3)
so(v, notNil)
so(err, isErr)
so(v.ValueType(), eq, NotExist)
Expand Down
2 changes: 1 addition & 1 deletion import_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (v *V) Export(dst any) error {
return json.Unmarshal(b, dst)
}

// Import convert json value from a marsalable parameter to *V. This a experimental function.
// Import convert json value from a marshal-able parameter to *V. This a experimental function.
//
// Import 将符合 encoding/json 的 struct 转为 *V 类型。不经过 encoding/json,并且支持 Option.
func Import(src any, opts ...Option) (*V, error) {
Expand Down
5 changes: 2 additions & 3 deletions import_export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func testImportExport(t *testing.T) {
cv("export to float", func() { testExportFloat(t) })
cv("export to bool", func() { testExportBool(t) })
cv("misc import", func() { testImport(t) })
cv("test structconv.go Import", func() { testStructConv_Import(t) })
cv("test struct conv.go Import", func() { testStructConv_Import(t) })

cv("test Issue 19", func() { testImportBugIssue19(t) })
cv("test Issue 22", func() { testImportBugIssue22(t) })
Expand Down Expand Up @@ -214,7 +214,7 @@ func testStructConv_Import(t *testing.T) {
cv("general types", func() { testStructConv_Import_NormalTypes(t) })
cv("array and slice", func() { testStructConv_Import_ArrayAndSlice(t) })
cv("json.Marshaler", func() { testStructConv_Import_JSONMarshaler(t) })
cv("encding.TextMarshaler", func() { testStructConv_Import_TextMarshaler(t) })
cv("encoding.TextMarshaler", func() { testStructConv_Import_TextMarshaler(t) })
}

func testStructConv_Import_RawAndBytes(t *testing.T) {
Expand Down Expand Up @@ -979,7 +979,6 @@ func testStructConv_Import_TextMarshaler(*testing.T) {
so(v.Len(), eq, 0)
so(v.MustMarshalString(), eq, "{}")
})
// TODO:
}

type customizedTextMarshaler struct {
Expand Down
Loading

0 comments on commit ff80771

Please sign in to comment.