OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1057 | 1057 |
1058 | 1058 |
1059 /** | 1059 /** |
1060 * A JavaScript string value (ECMA-262, 4.3.17). | 1060 * A JavaScript string value (ECMA-262, 4.3.17). |
1061 */ | 1061 */ |
1062 class String : public Primitive { | 1062 class String : public Primitive { |
1063 public: | 1063 public: |
1064 enum Encoding { | 1064 enum Encoding { |
1065 UNKNOWN_ENCODING = 0x1, | 1065 UNKNOWN_ENCODING = 0x1, |
1066 TWO_BYTE_ENCODING = 0x0, | 1066 TWO_BYTE_ENCODING = 0x0, |
1067 ASCII_ENCODING = 0x4 | 1067 ASCII_ENCODING = 0x4, |
| 1068 ONE_BYTE_ENCODING = 0x4 |
1068 }; | 1069 }; |
1069 /** | 1070 /** |
1070 * Returns the number of characters in this string. | 1071 * Returns the number of characters in this string. |
1071 */ | 1072 */ |
1072 V8EXPORT int Length() const; | 1073 V8EXPORT int Length() const; |
1073 | 1074 |
1074 /** | 1075 /** |
1075 * Returns the number of bytes in the UTF-8 encoded | 1076 * Returns the number of bytes in the UTF-8 encoded |
1076 * representation of this string. | 1077 * representation of this string. |
1077 */ | 1078 */ |
1078 V8EXPORT int Utf8Length() const; | 1079 V8EXPORT int Utf8Length() const; |
1079 | 1080 |
1080 /** | 1081 /** |
1081 * A fast conservative check for non-ASCII characters. May | 1082 * A fast conservative check for non-ASCII characters. May |
1082 * return true even for ASCII strings, but if it returns | 1083 * return true even for ASCII strings, but if it returns |
1083 * false you can be sure that all characters are in the range | 1084 * false you can be sure that all characters are in the range |
1084 * 0-127. | 1085 * 0-127. |
1085 */ | 1086 */ |
1086 V8EXPORT bool MayContainNonAscii() const; | 1087 V8EXPORT bool MayContainNonAscii() const; |
1087 | 1088 |
1088 /** | 1089 /** |
| 1090 * Returns whether this string contains only one byte data. |
| 1091 */ |
| 1092 V8EXPORT bool IsOneByte() const; |
| 1093 |
| 1094 /** |
1089 * Write the contents of the string to an external buffer. | 1095 * Write the contents of the string to an external buffer. |
1090 * If no arguments are given, expects the buffer to be large | 1096 * If no arguments are given, expects the buffer to be large |
1091 * enough to hold the entire string and NULL terminator. Copies | 1097 * enough to hold the entire string and NULL terminator. Copies |
1092 * the contents of the string and the NULL terminator into the | 1098 * the contents of the string and the NULL terminator into the |
1093 * buffer. | 1099 * buffer. |
1094 * | 1100 * |
1095 * WriteUtf8 will not write partial UTF-8 sequences, preferring to stop | 1101 * WriteUtf8 will not write partial UTF-8 sequences, preferring to stop |
1096 * before the end of the buffer. | 1102 * before the end of the buffer. |
1097 * | 1103 * |
1098 * Copies up to length characters into the output buffer. | 1104 * Copies up to length characters into the output buffer. |
(...skipping 21 matching lines...) Expand all Loading... |
1120 // 16-bit character codes. | 1126 // 16-bit character codes. |
1121 V8EXPORT int Write(uint16_t* buffer, | 1127 V8EXPORT int Write(uint16_t* buffer, |
1122 int start = 0, | 1128 int start = 0, |
1123 int length = -1, | 1129 int length = -1, |
1124 int options = NO_OPTIONS) const; | 1130 int options = NO_OPTIONS) const; |
1125 // ASCII characters. | 1131 // ASCII characters. |
1126 V8EXPORT int WriteAscii(char* buffer, | 1132 V8EXPORT int WriteAscii(char* buffer, |
1127 int start = 0, | 1133 int start = 0, |
1128 int length = -1, | 1134 int length = -1, |
1129 int options = NO_OPTIONS) const; | 1135 int options = NO_OPTIONS) const; |
| 1136 // One byte characters. |
| 1137 V8EXPORT int WriteOneByte(uint8_t* buffer, |
| 1138 int start = 0, |
| 1139 int length = -1, |
| 1140 int options = NO_OPTIONS) const; |
1130 // UTF-8 encoded characters. | 1141 // UTF-8 encoded characters. |
1131 V8EXPORT int WriteUtf8(char* buffer, | 1142 V8EXPORT int WriteUtf8(char* buffer, |
1132 int length = -1, | 1143 int length = -1, |
1133 int* nchars_ref = NULL, | 1144 int* nchars_ref = NULL, |
1134 int options = NO_OPTIONS) const; | 1145 int options = NO_OPTIONS) const; |
1135 | 1146 |
1136 /** | 1147 /** |
1137 * A zero length string. | 1148 * A zero length string. |
1138 */ | 1149 */ |
1139 V8EXPORT static v8::Local<v8::String> Empty(); | 1150 V8EXPORT static v8::Local<v8::String> Empty(); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1221 */ | 1232 */ |
1222 virtual ~ExternalAsciiStringResource() {} | 1233 virtual ~ExternalAsciiStringResource() {} |
1223 /** The string data from the underlying buffer.*/ | 1234 /** The string data from the underlying buffer.*/ |
1224 virtual const char* data() const = 0; | 1235 virtual const char* data() const = 0; |
1225 /** The number of ASCII characters in the string.*/ | 1236 /** The number of ASCII characters in the string.*/ |
1226 virtual size_t length() const = 0; | 1237 virtual size_t length() const = 0; |
1227 protected: | 1238 protected: |
1228 ExternalAsciiStringResource() {} | 1239 ExternalAsciiStringResource() {} |
1229 }; | 1240 }; |
1230 | 1241 |
| 1242 typedef ExternalAsciiStringResource ExternalOneByteStringResource; |
| 1243 |
1231 /** | 1244 /** |
1232 * If the string is an external string, return the ExternalStringResourceBase | 1245 * If the string is an external string, return the ExternalStringResourceBase |
1233 * regardless of the encoding, otherwise return NULL. The encoding of the | 1246 * regardless of the encoding, otherwise return NULL. The encoding of the |
1234 * string is returned in encoding_out. | 1247 * string is returned in encoding_out. |
1235 */ | 1248 */ |
1236 V8_INLINE(ExternalStringResourceBase* GetExternalStringResourceBase( | 1249 V8_INLINE(ExternalStringResourceBase* GetExternalStringResourceBase( |
1237 Encoding* encoding_out) const); | 1250 Encoding* encoding_out) const); |
1238 | 1251 |
1239 /** | 1252 /** |
1240 * Get the ExternalStringResource for an external string. Returns | 1253 * Get the ExternalStringResource for an external string. Returns |
(...skipping 3621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4862 | 4875 |
4863 | 4876 |
4864 } // namespace v8 | 4877 } // namespace v8 |
4865 | 4878 |
4866 | 4879 |
4867 #undef V8EXPORT | 4880 #undef V8EXPORT |
4868 #undef TYPE_CHECK | 4881 #undef TYPE_CHECK |
4869 | 4882 |
4870 | 4883 |
4871 #endif // V8_H_ | 4884 #endif // V8_H_ |
OLD | NEW |