📄 pstring.h
字号:
PString Left( PINDEX len /// Number of characters to extract. ) const; /**Extract a portion of the string into a new string. The original string is not changed and a new unique reference to a string is returned. A substring from the end of the string for the number of characters specified is extracted. If #len# is greater than the length of the string then all characters to the beginning of the string are returned. If #len# is zero then an empty string is returned. @return substring of the source string. */ PString Right( PINDEX len /// Number of characters to extract. ) const; /**Extract a portion of the string into a new string. The original string is not changed and a new unique reference to a string is returned. A substring from the #start# position for the number of characters specified is extracted. If #len# is greater than the length of the string from the #start# position then all characters to the end of the string are returned. If #start# is greater than the length of the string or #len# is zero then an empty string is returned. @return substring of the source string. */ PString Mid( PINDEX start, /// Starting position of the substring. PINDEX len = P_MAX_INDEX /// Number of characters to extract. ) const; /**Create a string consisting of all characters from the source string except all spaces at the beginning of the string. The original string is not changed and a new unique reference to a string is returned. @return string with leading spaces removed. */ PString LeftTrim() const; /**Create a string consisting of all characters from the source string except all spaces at the end of the string. The original string is not changed and a new unique reference to a string is returned. @return string with trailing spaces removed. */ PString RightTrim() const; /**Create a string consisting of all characters from the source string except all spaces at the beginning and end of the string. The original string is not changed and a new unique reference to a string is returned. @return string with leading and trailing spaces removed. */ PString Trim() const; /**Create a string consisting of all characters from the source string with all upper case letters converted to lower case. The original string is not changed and a new unique reference to a string is returned. @return string with upper case converted to lower case. */ PString ToLower() const; /**Create a string consisting of all characters from the source string with all lower case letters converted to upper case. The original string is not changed and a new unique reference to a string is returned. @return string with lower case converted to upper case. */ PString ToUpper() const; /** Split the string into an array of substrings. */ PStringArray Tokenise( const PString & separators, /// A string for the set of separator characters that delimit tokens. BOOL onePerSeparator = TRUE /// Flag for if there are empty tokens between consecutive separators. ) const; /**Split the string into an array of substrings. Divide the string into an array of substrings delimited by characters from the specified set. There are two options for the tokenisation, the first is where the #onePerSeparator# is TRUE. This form will produce a token for each delimiter found in the set. Thus the string ",two,three,,five" would be split into 5 substrings; "", "two", "three", "" and "five". The second form where #onePerSeparator# is FALSE is used where consecutive delimiters do not constitute a empty token. In this case the string " a list of words " would be split into 4 substrings; "a", "list", "of" and "words". There is an important distinction when there are delimiters at the beginning or end of the source string. In the first case there will be empty strings at the end of the array and in the second the delimiters are ignored. @return an array of substring for each token in the string. */ PStringArray Tokenise( const char * cseparators, /// A C string for the set of separator characters that delimit tokens. BOOL onePerSeparator = TRUE /// Flag for if there are empty tokens between consecutive separators. ) const; /**Split the string into individual lines. The line delimiters may be a carriage return ('\r'), a line feed ('\n') or a carriage return and line feed pair ("\r\n"). A line feed and carriage return pair ("\n\r") would yield a blank line. between the characters. The #Tokenise()# function should not be used to split a string into lines as a #"\r\n"# pair consitutes a single line ending. The #Tokenise()# function would produce a blank line in between them. @return string array with a substring for each line in the string. */ PStringArray Lines() const; //@} /**@name Conversion functions */ //@{ /**Concatenate a formatted output to the string. This is identical to the standard C library #sprintf()# function, but appends its output to the string. This function makes the assumption that there is less the 1000 characters of formatted output. The function will assert if this occurs. Note that this function will break the current instance from multiple references to the string. A new string buffer is allocated and the data from the old string buffer copied to it. @return reference to the current string object. */ PString & sprintf( const char * cfmt, /// C string for output format. ... /// Extra parameters for #sprintf()# call. ); /**Produce formatted output as a string. This is identical to the standard C library #sprintf()# function, but sends its output to a #PString#. This function makes the assumption that there is less the 1000 characters of formatted output. The function will assert if this occurs. Note that this function will break the current instance from multiple references to the string. A new string buffer is allocated and the data from the old string buffer copied to it. @return reference to the current string object. */ friend PString psprintf( const char * cfmt, /// C string for output format. ... /// Extra parameters for #sprintf()# call. ); /** Concatenate a formatted output to the string. */ PString & vsprintf( const PString & fmt, /// String for output format. va_list args /// Extra parameters for #sprintf()# call. ); /**Concatenate a formatted output to the string. This is identical to the standard C library #vsprintf()# function, but appends its output to the string. This function makes the assumption that there is less the 1000 characters of formatted output. The function will assert if this occurs. Note that this function will break the current instance from multiple references to the string. A new string buffer is allocated and the data from the old string buffer copied to it. @return reference to the current string object. */ PString & vsprintf( const char * cfmt, /// C string for output format. va_list args /// Extra parameters for #sprintf()# call. ); /** Produce formatted output as a string. */ friend PString pvsprintf( const char * cfmt, /// C string for output format. va_list args /// Extra parameters for #sprintf()# call. ); /**Produce formatted output as a string. This is identical to the standard C library #vsprintf()# function, but sends its output to a #PString#. This function makes the assumption that there is less the 1000 characters of formatted output. The function will assert if this occurs. Note that this function will break the current instance from multiple references to the string. A new string buffer is allocated and the data from the old string buffer copied to it. @return reference to the current string object. */ friend PString pvsprintf( const PString & fmt, /// String for output format. va_list args /// Extra parameters for #sprintf()# call. ); /**Convert the string to an integer value using the specified number base. All characters up to the first illegal character for the number base are converted. Case is not significant for bases greater than 10. The number base may only be from 2 to 36 and the function will assert if it is not in this range. This function uses the standard C library #strtol()# function. @return integer value for the string. */ long AsInteger( unsigned base = 10 /// Number base to convert the string in. ) const; /**Convert the string to an integer value using the specified number base. All characters up to the first illegal character for the number base are converted. Case is not significant for bases greater than 10. The number base may only be from 2 to 36 and the function will assert if it is not in this range. This function uses the standard C library #strtoul()# function. @return integer value for the string. */ DWORD AsUnsigned( unsigned base = 10 /// Number base to convert the string in. ) const; /**Convert the string to an integer value using the specified number base. All characters up to the first illegal character for the number base are converted. Case is not significant for bases greater than 10. The number base may only be from 2 to 36 and the function will assert if it is not in this range. This function uses the standard C library #strtoq()# or #strtoul()# function. @return integer value for the string. */ PInt64 AsInt64( unsigned base = 10 /// Number base to convert the string in. ) const; /**Convert the string to an integer value using the specified number base. All characters up to the first illegal character for the number base are converted. Case is not significant for bases greater than 10. The number base may only be from 2 to 36 and the function will assert if it is not in this range. This function uses the standard C library #strtouq()# or #strtoul()# function. @return integer value for the string. */ PUInt64 AsUnsigned64( unsigned base = 10 /// Number base to convert the string in. ) const; /**Convert the string to a floating point number. This number may be in decimal or exponential form. All characters up to the first illegal character for a floting point number are converted. This function uses the standard C library #strtod()# function. @return floating point value for the string. */ double AsReal() const; /**Convert a standard null terminated string to a "pascal" style string. This consists of a songle byte for the length of the string and then the string characters following it. This function will assert if the string is greater than 255 characters in length. @return byte array containing the "pascal" style string. */ PBYTEArray ToPascal() const; /**Convert the string to C literal string format. This will convert non printable characters to the \nnn form or for standard control characters such as line feed, to \n form. Any '"' characters are also escaped with a \ character and the entire string is enclosed in '"' characters. @return string converted to a C language literal form. */ PString ToLiteral() const;#ifndef PHAS_UNICODE /**Get the internal buffer as a pointer to unsigned characters. The standard "operator const char *" function is provided by the #PCharArray# ancestor class. @return pointer to character buffer. */ operator const unsigned char *() const;#endif //@} protected: virtual Comparison InternalCompare( PINDEX offset, // Offset into string to compare. char c // Character to compare against. ) const; virtual Comparison InternalCompare( PINDEX offset, // Offset into string to compare. PINDEX length, // Number of characters to compare. const char * cstr // C string to compare against. ) const; /* Internal function to compare the current string value against the specified C string. @return relative rank of the two strings. */ PString(int dummy, const PString * str);};///////////////////////////////////////////////////////////////////////////////**This class is a variation of a string that ignores case. Thus in all standard comparison (#==#, #<# etc) and search (#Find()# etc) functions the case of the characters and strings is ignored. The characters in the string still maintain their case. Only the comparison operations are affected. So printing etc will still display the string as entered. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -