|
7 | 7 | "sort"
|
8 | 8 | "strconv"
|
9 | 9 | "strings"
|
10 |
| - "unicode/utf8" |
11 | 10 | )
|
12 | 11 |
|
13 | 12 | // MarshalOptions must be provided when invoking Marshal(). Use
|
@@ -92,33 +91,14 @@ func MarshalFloat(value float64, bitSize int) []byte {
|
92 | 91 | // echo serialize('Hello world');
|
93 | 92 | // // s:11:"Hello world";
|
94 | 93 | //
|
95 |
| -// Non ASCII characters will be escaped in the output, so the result will always |
96 |
| -// be an ASCII string: |
97 |
| -// |
98 |
| -// MarshalString("Björk Guðmundsdóttir"); |
99 |
| -// // s:23:"Bj\xc3\xb6rk Gu\xc3\xb0mundsd\xc3\xb3ttir"; |
100 |
| -// |
101 | 94 | // The same result would be returned by marshalling a string value:
|
102 | 95 | //
|
103 | 96 | // Marshal('Hello world')
|
104 | 97 | //
|
105 | 98 | // One important distinction is that PHP stores binary data in strings. See
|
106 | 99 | // MarshalBytes for more information.
|
107 | 100 | func MarshalString(value string) []byte {
|
108 |
| - var buffer bytes.Buffer |
109 |
| - for _, r := range value { |
110 |
| - if r <= 127 { |
111 |
| - buffer.WriteRune(r) |
112 |
| - } else { |
113 |
| - chars := make([]byte, 4) |
114 |
| - for i := 0; i < utf8.EncodeRune(chars, r); i++ { |
115 |
| - escapedChar := fmt.Sprintf("\\x%02x", chars[i]) |
116 |
| - buffer.WriteString(escapedChar) |
117 |
| - } |
118 |
| - } |
119 |
| - } |
120 |
| - |
121 |
| - return []byte(fmt.Sprintf("s:%d:\"%s\";", len(value), buffer.String())) |
| 101 | + return []byte(fmt.Sprintf("s:%d:\"%s\";", len(value), value)) |
122 | 102 | }
|
123 | 103 |
|
124 | 104 | // MarshalBytes returns the bytes to represent a PHP serialized string value
|
|
0 commit comments