|
@@ -13,6 +13,7 @@ import (
|
|
|
"unicode/utf8"
|
|
"unicode/utf8"
|
|
|
|
|
|
|
|
"google.golang.org/protobuf/internal/errors"
|
|
"google.golang.org/protobuf/internal/errors"
|
|
|
|
|
+ "google.golang.org/protobuf/internal/strs"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
func appendString(out []byte, in string) ([]byte, error) {
|
|
func appendString(out []byte, in string) ([]byte, error) {
|
|
@@ -136,18 +137,4 @@ func indexNeedEscapeInString(s string) int {
|
|
|
}
|
|
}
|
|
|
return len(s)
|
|
return len(s)
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-// indexNeedEscapeInBytes returns the index of the character that needs
|
|
|
|
|
-// escaping. If no characters need escaping, this returns the input length.
|
|
|
|
|
-// TODO: Remove this duplicate function when https://golang.org/issue/31506 gets
|
|
|
|
|
-// resolved.
|
|
|
|
|
-func indexNeedEscapeInBytes(b []byte) int {
|
|
|
|
|
- for i := 0; i < len(b); {
|
|
|
|
|
- r, n := utf8.DecodeRune(b[i:])
|
|
|
|
|
- if r < ' ' || r == '\\' || r == '"' || r == utf8.RuneError {
|
|
|
|
|
- return i
|
|
|
|
|
- }
|
|
|
|
|
- i += n
|
|
|
|
|
- }
|
|
|
|
|
- return len(b)
|
|
|
|
|
-}
|
|
|
|
|
|
|
+func indexNeedEscapeInBytes(b []byte) int { return indexNeedEscapeInString(strs.UnsafeString(b)) }
|