📄 ustring.h
字号:
*/ UString(const UChar *c, int length); /** * If copy is false the string data will be adopted. * That means that the data will NOT be copied and the pointer will * be deleted when the UString object is modified or destroyed. * Behaviour defaults to a deep copy if copy is true. */ UString(UChar *c, int length, bool copy); /** * Copy constructor. Makes a shallow copy only. */ UString(const UString &s) { attach(s.rep); } /** * Convenience declaration only ! You'll be on your own to write the * implementation for a construction from QString. * * Note: feel free to contact me if you want to see a dummy header for * your favourite FooString class here ! */ UString(const QString &); /** * Convenience declaration only ! See @ref UString(const QString&). */ UString(const DOM::DOMString &); /** * Concatenation constructor. Makes operator+ more efficient. */ UString(const UString &, const UString &); /** * Destructor. If this handle was the only one holding a reference to the * string the data will be freed. */ ~UString() { release(); } /** * Constructs a string from an int. */ static UString from(int i); /** * Constructs a string from an unsigned int. */ static UString from(unsigned int u); /** * Constructs a string from a long. */ static UString from(long l); /** * Constructs a string from a double. */ static UString from(double d); /** * Append another string. */ UString &append(const UString &); UString &append(const char *); UString &append(unsigned short); UString &append(char c) { return append(static_cast<unsigned short>(static_cast<unsigned char>(c))); } UString &append(UChar c) { return append(c.uc); } /** * @return The string converted to the 8-bit string type @ref CString(). */ CString cstring() const; /** * Convert the Unicode string to plain ASCII chars chopping of any higher * bytes. This method should only be used for *debugging* purposes as it * is neither Unicode safe nor free from side effects. In order not to * waste any memory the char buffer is static and *shared* by all UString * instances. */ char *ascii() const; /** * Convert the string to UTF-8, assuming it is UTF-16 encoded. * Since this function is tolerant of badly formed UTF-16, it can create UTF-8 * strings that are invalid because they have characters in the range * U+D800-U+DDFF, U+FFFE, or U+FFFF, but the UTF-8 string is guaranteed to * be otherwise valid. */ CString UTF8String() const; /** * @see UString(const QString&). */ DOM::DOMString string() const; /** * @see UString(const QString&). */ QString qstring() const; /** * @see UString(const QString&). */ QConstString qconststring() const; /** * Assignment operator. */ UString &operator=(const char *c); UString &operator=(const UString &); /** * Appends the specified string. */ UString &operator+=(const UString &s) { return append(s); } UString &operator+=(const char *s) { return append(s); } /** * @return A pointer to the internal Unicode data. */ const UChar* data() const { return rep->data(); } /** * @return True if null. */ bool isNull() const { return (rep == &Rep::null); } /** * @return True if null or zero length. */ bool isEmpty() const { return (!rep->len); } /** * Use this if you want to make sure that this string is a plain ASCII * string. For example, if you don't want to lose any information when * using @ref cstring() or @ref ascii(). * * @return True if the string doesn't contain any non-ASCII characters. */ bool is8Bit() const; /** * @return The length of the string. */ int size() const { return rep->size(); } /** * Const character at specified position. */ UChar operator[](int pos) const; /** * Writable reference to character at specified position. */ UCharReference operator[](int pos); /** * Attempts an conversion to a number. Apart from floating point numbers, * the algorithm will recognize hexadecimal representations (as * indicated by a 0x or 0X prefix) and +/- Infinity. * Returns NaN if the conversion failed. * @param tolerateTrailingJunk if true, toDouble can tolerate garbage after the number. * @param tolerateEmptyString if false, toDouble will turn an empty string into NaN rather than 0. */ double toDouble(bool tolerateTrailingJunk, bool tolerateEmptyString) const; double toDouble(bool tolerateTrailingJunk) const; double toDouble() const; /** * Attempts an conversion to an unsigned long integer. ok will be set * according to the success. * @param tolerateEmptyString if false, toULong will return false for *ok for an empty string. */ unsigned long toULong(bool *ok, bool tolerateEmptyString) const; unsigned long toULong(bool *ok = 0) const; uint32_t toUInt32(bool *ok = 0) const; uint32_t toStrictUInt32(bool *ok = 0) const; /** * Attempts an conversion to an array index. The "ok" boolean will be set * to true if it is a valid array index according to the rule from * ECMA 15.2 about what an array index is. It must exactly match the string * form of an unsigned integer, and be less than 2^32 - 1. */ unsigned toArrayIndex(bool *ok = 0) const; /** * @return Position of first occurrence of f starting at position pos. * -1 if the search was not successful. */ int find(const UString &f, int pos = 0) const; int find(UChar, int pos = 0) const; /** * @return Position of first occurrence of f searching backwards from * position pos. * -1 if the search was not successful. */ int rfind(const UString &f, int pos) const; int rfind(UChar, int pos) const; /** * @return The sub string starting at position pos and length len. */ UString substr(int pos = 0, int len = -1) const; /** * Static instance of a null string. */ static const UString &null();#ifdef KJS_DEBUG_MEM /** * Clear statically allocated resources. */ static void globalClear();#endif private: UString(Rep *r) { attach(r); } void attach(Rep *r); void detach(); void release(); int expandedSize(int size, int otherSize) const; int usedCapacity() const; int usedPreCapacity() const; void expandCapacity(int requiredLength); void expandPreCapacity(int requiredPreCap); Rep *rep; }; inline bool operator==(const UChar &c1, const UChar &c2) { return (c1.uc == c2.uc); } bool operator==(const UString& s1, const UString& s2); inline bool operator!=(const UString& s1, const UString& s2) { return !KJS::operator==(s1, s2); } bool operator<(const UString& s1, const UString& s2); bool operator==(const UString& s1, const char *s2); inline bool operator!=(const UString& s1, const char *s2) { return !KJS::operator==(s1, s2); } inline bool operator==(const char *s1, const UString& s2) { return operator==(s2, s1); } inline bool operator!=(const char *s1, const UString& s2) { return !KJS::operator==(s1, s2); } bool operator==(const CString& s1, const CString& s2); inline UString operator+(const UString& s1, const UString& s2) { return UString(s1, s2); } int compare(const UString &, const UString &); // Given a first byte, gives the length of the UTF-8 sequence it begins. // Returns 0 for bytes that are not legal starts of UTF-8 sequences. // Only allows sequences of up to 4 bytes, since that works for all Unicode characters (U-00000000 to U-0010FFFF). int UTF8SequenceLength(char); // Takes a null-terminated C-style string with a UTF-8 sequence in it and converts it to a character. // Only allows Unicode characters (U-00000000 to U-0010FFFF). // Returns -1 if the sequence is not valid (including presence of extra bytes). int decodeUTF8Sequence(const char *); // Given a UTF-8 string, converts offsets from the UTF-16 form of the string into offsets into the UTF-8 string. // Note: This function can overrun the buffer if the string contains a partial UTF-8 sequence, so it should // not be called with strings that might contain such sequences. void convertUTF16OffsetsToUTF8Offsets(const char *UTF8String, int *offsets, int numOffsets); // Given a UTF-8 string, converts offsets from the UTF-8 string into offsets into the UTF-16 form of the string. // Note: This function can overrun the buffer if the string contains a partial UTF-8 sequence, so it should // not be called with strings that might contain such sequences. void convertUTF8OffsetsToUTF16Offsets(const char *UTF8String, int *offsets, int numOffsets);}; // namespace#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -