pstring.h
来自「开源代码的pwlib的1.10.0版本,使用openh323的1.18.0版本毕」· C头文件 代码 · 共 1,755 行 · 第 1/5 页
H
1,755 行
function will do nothing.
The matching will be for identical character or string. If a search
ignoring case is required then the string should be converted to a
#PCaselessString# before the search is made.
*/
void Replace(
const PString & target, ///< Text to be removed.
const PString & subs, ///< String to be inserted into the gaps created
BOOL all = FALSE, ///< Replace all occurrences of target text.
PINDEX offset = 0 ///< Offset into string to begin search.
);
/**Splice the string into the current string at the specified position. The
specified number of bytes are removed from the string.
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.
*/
void Splice(
const PString & str, ///< Substring to insert.
PINDEX pos, ///< Position in string to insert the substring.
PINDEX len = 0 ///< Length of section to remove.
);
/**Splice the string into the current string at the specified position. The
specified number of bytes are removed from the string.
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.
*/
void Splice(
const char * cstr, ///< Substring to insert.
PINDEX pos, ///< Position in string to insert the substring.
PINDEX len = 0 ///< Length of section to remove.
);
/**Remove the substring from the string.
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.
*/
void Delete(
PINDEX start, ///< Position in string to remove.
PINDEX len ///< Number of characters to delete.
);
//@}
/**@name Sub-string functions */
//@{
/**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.
The substring is returned inclusive of the characters at the
#start# and #end# positions.
If the #end# position is greater than the length of the
string then all characters from the #start# up to the end of
the string are returned.
If #start# is greater than the length of the string or
#end# is before #start# then an empty string is
returned.
@return
substring of the source string.
*/
PString operator()(
PINDEX start, ///< Starting position of the substring.
PINDEX end ///< Ending position of the substring.
) 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 beginning 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 end of the string are returned.
If #len# is zero then an empty string is returned.
@return
substring of the source string.
*/
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
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?