VirtualBox

Changeset 13472 in vbox for trunk/include


Ignore:
Timestamp:
Oct 22, 2008 9:19:00 AM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
38270
Message:

IPRT: Added a couple of function for simple string pattern matching (from STAM).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/string.h

    r10951 r13472  
    722722RTDECL(char *) RTStrStripR(char *psz);
    723723
     724/**
     725 * Performs a case sensitive string compare between two UTF-8 strings.
     726 *
     727 * Encoding errors are ignored by the current implementation. So, the only
     728 * difference between this and the CRT strcmp function is the handling of
     729 * NULL arguments.
     730 *
     731 * @returns < 0 if the first string less than the second string.
     732 * @returns 0 if the first string identical to the second string.
     733 * @returns > 0 if the first string greater than the second string.
     734 * @param   psz1        First UTF-8 string. Null is allowed.
     735 * @param   psz2        Second UTF-8 string. Null is allowed.
     736 */
     737RTDECL(int) RTStrCmp(const char *psz1, const char *psz2);
     738
     739/**
     740 * Performs a case insensitive string compare between two UTF-8 strings.
     741 *
     742 * This is a simplified compare, as only the simplified lower/upper case folding
     743 * specified by the unicode specs are used. It does not consider character pairs
     744 * as they are used in some languages, just simple upper & lower case compares.
     745 *
     746 * The result is the difference between the mismatching codepoints after they
     747 * both have been lower cased.
     748 *
     749 * If the string encoding is invalid the function will assert (strict builds)
     750 * and use RTStrCmp for the remainder of the string.
     751 *
     752 * @returns < 0 if the first string less than the second string.
     753 * @returns 0 if the first string identical to the second string.
     754 * @returns > 0 if the first string greater than the second string.
     755 * @param   psz1        First UTF-8 string. Null is allowed.
     756 * @param   psz2        Second UTF-8 string. Null is allowed.
     757 */
     758RTDECL(int) RTStrICmp(const char *psz1, const char *psz2);
     759
     760/**
     761 * Find the length of a zero-terminated byte string, given
     762 * a max string length.
     763 *
     764 * See also RTStrNLenEx.
     765 *
     766 * @returns The string length or cbMax. The returned length does not include
     767 *          the zero terminator if it was found.
     768 *
     769 * @param   pszString   The string.
     770 * @param   cchMax      The max string length.
     771 */
     772RTDECL(size_t) RTStrNLen(const char *pszString, size_t cchMax);
     773
     774/**
     775 * Find the length of a zero-terminated byte string, given
     776 * a max string length.
     777 *
     778 * See also RTStrNLen.
     779 *
     780 * @returns IPRT status code.
     781 * @retval  VINF_SUCCESS if the string has a length less than cchMax.
     782 * @retval  VERR_BUFFER_OVERFLOW if the end of the string wasn't found
     783 *          before cchMax was reached.
     784 *
     785 * @param   pszString   The string.
     786 * @param   cchMax      The max string length.
     787 * @param   pcch        Where to store the string length excluding the
     788 *                      terminator. This is set to cchMax if the terminator
     789 *                      isn't found.
     790 */
     791RTDECL(int) RTStrNLenEx(const char *pszString, size_t cchMax, size_t *pcch);
     792
     793/**
     794 * Matches a simple string pattern.
     795 *
     796 * @returns true if the string matches the pattern, otherwise false.
     797 *
     798 * @param  pszPattern   The pattern. Special chars are '*' and '?', where the
     799 *                      asterisk matches zero or more characters and question
     800 *                      mark matches exactly one character.
     801 * @param  pszString    The string to match against the pattern.
     802 */
     803RTDECL(bool) RTStrSimplePatternMatch(const char *pszPattern, const char *pszString);
     804
     805/**
     806 * Matches a simple string pattern, neither which needs to be zero terminated.
     807 *
     808 * This is identical to RTStrSimplePatternMatch except that you can optionally
     809 * specify the length of both the pattern and the string.  The function will
     810 * stop when it hits a string terminator or either of the lengths.
     811 *
     812 * @returns true if the string matches the pattern, otherwise false.
     813 *
     814 * @param  pszPattern   The pattern. Special chars are '*' and '?', where the
     815 *                      asterisk matches zero or more characters and question
     816 *                      mark matches exactly one character.
     817 * @param  cchPattern   The pattern length. Pass SIZE_T_MAX (~(size_t)0) if you
     818 *                      don't know the length and wish to stop at the string
     819 *                      terminator.
     820 * @param  pszString    The string to match against the pattern.
     821 * @param  cchString    The string length. Pass SIZE_T_MAX (~(size_t)0) if you
     822 *                      don't know the length and wish to match up to the string
     823 *                      terminator.
     824 */
     825RTDECL(bool) RTStrSimplePatternNMatch(const char *pszPattern, size_t cchPattern,
     826                                      const char *pszString, size_t cchString);
     827
     828/**
     829 * Matches multiple patterns against a string.
     830 *
     831 * The patterns are separated by the pipe character (|).
     832 *
     833 * @returns true if the string matches the pattern, otherwise false.
     834 *
     835 * @param   pszPatterns The patterns.
     836 * @param   cchPatterns The lengths of the patterns to use. Pass SIZE_T_MAX
     837 *                      (~(size_t)0) to stop at the terminator.
     838 * @param   pszString   The string to match against the pattern.
     839 * @param   cchString   The string length. Pass SIZE_T_MAX (~(size_t)0) stop
     840 *                      stop at the terminator.
     841 * @param   poffPattern Offset into the patterns string of the patttern that
     842 *                      matched. If no match, this will be set to SIZE_T_MAX.
     843 *                      This is optional, NULL is fine.
     844 */
     845RTDECL(bool) RTStrSimplePatternMultiMatch(const char *pszPatterns, size_t cchPatterns,
     846                                          const char *pszString, size_t cchString,
     847                                          size_t *poffPattern);
     848
    724849
    725850/** @defgroup rt_str_conv   String To/From Number Conversions
     
    11181243 */
    11191244RTDECL(int8_t) RTStrToInt8(const char *pszValue);
    1120 
    1121 /**
    1122  * Performs a case sensitive string compare between two UTF-8 strings.
    1123  *
    1124  * Encoding errors are ignored by the current implementation. So, the only
    1125  * difference between this and the CRT strcmp function is the handling of
    1126  * NULL arguments.
    1127  *
    1128  * @returns < 0 if the first string less than the second string.
    1129  * @returns 0 if the first string identical to the second string.
    1130  * @returns > 0 if the first string greater than the second string.
    1131  * @param   psz1        First UTF-8 string. Null is allowed.
    1132  * @param   psz2        Second UTF-8 string. Null is allowed.
    1133  */
    1134 RTDECL(int) RTStrCmp(const char *psz1, const char *psz2);
    1135 
    1136 /**
    1137  * Performs a case insensitive string compare between two UTF-8 strings.
    1138  *
    1139  * This is a simplified compare, as only the simplified lower/upper case folding
    1140  * specified by the unicode specs are used. It does not consider character pairs
    1141  * as they are used in some languages, just simple upper & lower case compares.
    1142  *
    1143  * The result is the difference between the mismatching codepoints after they
    1144  * both have been lower cased.
    1145  *
    1146  * If the string encoding is invalid the function will assert (strict builds)
    1147  * and use RTStrCmp for the remainder of the string.
    1148  *
    1149  * @returns < 0 if the first string less than the second string.
    1150  * @returns 0 if the first string identical to the second string.
    1151  * @returns > 0 if the first string greater than the second string.
    1152  * @param   psz1        First UTF-8 string. Null is allowed.
    1153  * @param   psz2        Second UTF-8 string. Null is allowed.
    1154  */
    1155 RTDECL(int) RTStrICmp(const char *psz1, const char *psz2);
    1156 
    1157 /**
    1158  * Find the length of a zero-terminated byte string, given
    1159  * a max string length.
    1160  *
    1161  * See also RTStrNLenEx.
    1162  *
    1163  * @returns The string length or cbMax. The returned length does not include
    1164  *          the zero terminator if it was found.
    1165  *
    1166  * @param   pszString   The string.
    1167  * @param   cchMax      The max string length.
    1168  */
    1169 RTDECL(size_t) RTStrNLen(const char *pszString, size_t cchMax);
    1170 
    1171 /**
    1172  * Find the length of a zero-terminated byte string, given
    1173  * a max string length.
    1174  *
    1175  * See also RTStrNLen.
    1176  *
    1177  * @returns IPRT status code.
    1178  * @retval  VINF_SUCCESS if the string has a length less than cchMax.
    1179  * @retval  VERR_BUFFER_OVERFLOW if the end of the string wasn't found
    1180  *          before cchMax was reached.
    1181  *
    1182  * @param   pszString   The string.
    1183  * @param   cchMax      The max string length.
    1184  * @param   pcch        Where to store the string length excluding the
    1185  *                      terminator. This is set to cchMax if the terminator
    1186  *                      isn't found.
    1187  */
    1188 RTDECL(int) RTStrNLenEx(const char *pszString, size_t cchMax, size_t *pcch);
    11891245
    11901246/** @} */
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette