VirtualBox

Changeset 31418 in vbox for trunk/include


Ignore:
Timestamp:
Aug 5, 2010 5:37:13 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
64483
Message:

iprt/string.h,utf-8.cpp: avoid including uni.h; misc nits.

Location:
trunk/include/iprt
Files:
3 edited

Legend:

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

    r31246 r31418  
    3131#include <iprt/assert.h>
    3232#include <iprt/stdarg.h>
    33 #include <iprt/uni.h> /* for RTUNICP_INVALID */
    3433#include <iprt/err.h> /* for VINF_SUCCESS */
    3534#if defined(RT_OS_LINUX) && defined(__KERNEL__)
     
    6867#endif
    6968
     69
     70/** @def RT_USE_RTC_3629
     71 * When defined the UTF-8 range will stop at  0x10ffff.  If not defined, the
     72 * range stops at 0x7fffffff.
     73 * @remarks Must be defined both when building and using the IPRT.  */
     74#ifdef DOXYGEN_RUNNING
     75# define RT_USE_RTC_3629
     76#endif
     77
     78
    7079/**
    7180 * Byte zero the specified object.
     
    100109 */
    101110#define RT_BZERO(pv, cb)    do { memset((pv), 0, cb); } while (0)
     111
    102112
    103113
     
    823833 *
    824834 * This function will validate the string, and incorrectly encoded UTF-8
    825  * strings will be rejected. The primary purpose of this function is to
    826  * help allocate buffers for RTStrToLatin1Ex of the correct size. For most
    827  * other purposes RTStrCalcLatin1LenEx() should be used.
     835 * strings as well as string with codepoints outside the latin-1 range will be
     836 * rejected.  The primary purpose of this function is to help allocate buffers
     837 * for RTStrToLatin1Ex of the correct size.  For most other purposes
     838 * RTStrCalcLatin1LenEx() should be used.
    828839 *
    829840 * @returns Number of Latin-1 characters.
     
    837848 *
    838849 * This function will validate the string, and incorrectly encoded UTF-8
    839  * strings will be rejected.
     850 * strings as well as string with codepoints outside the latin-1 range will be
     851 * rejected.
    840852 *
    841853 * @returns iprt status code.
    842854 * @param   psz         The string.
    843  * @param   cch         The max string length. Use RTSTR_MAX to process the entire string.
     855 * @param   cch         The max string length. Use RTSTR_MAX to process the
     856 *                      entire string.
    844857 * @param   pcch        Where to store the string length. Optional.
    845858 *                      This is undefined on failure.
     
    875888 * @returns iprt status code.
    876889 * @param   pszString       UTF-8 string to convert.
    877  * @param   cchString       The maximum size in chars (the type) to convert. The conversion stop
    878  *                          when it reaches cchString or the string terminator ('\\0').
    879  *                          Use RTSTR_MAX to translate the entire string.
    880  * @param   ppsz            If cch is non-zero, this must either be pointing to pointer to
    881  *                          a buffer of the specified size, or pointer to a NULL pointer.
    882  *                          If *ppsz is NULL or cch is zero a buffer of at least cch items
    883  *                          will be allocated to hold the translated string.
    884  *                          If a buffer was requested it must be freed using RTStrFree().
    885  * @param   cch             The buffer size in bytes. This includes the terminator.
     890 * @param   cchString       The maximum size in chars (the type) to convert.
     891 *                          The conversion stop when it reaches cchString or
     892 *                          the string terminator ('\\0'). Use RTSTR_MAX to
     893 *                          translate the entire string.
     894 * @param   ppsz            If cch is non-zero, this must either be pointing to
     895 *                          pointer to a buffer of the specified size, or
     896 *                          pointer to a NULL pointer.  If *ppsz is NULL or cch
     897 *                          is zero a buffer of at least cch items will be
     898 *                          allocated to hold the translated string. If a
     899 *                          buffer was requested it must be freed using
     900 *                          RTStrFree().
     901 * @param   cch             The buffer size in bytes. This includes the
     902 *                          terminator.
    886903 * @param   pcch            Where to store the length of the translated string,
    887904 *                          excluding the terminator. (Optional)
     
    901918 * @returns iprt status code.
    902919 * @param   pszString       UTF-8 string to convert.
    903  * @param   cchString       The maximum size in chars (the type) to convert. The conversion stop
    904  *                          when it reaches cchString or the string terminator ('\\0').
    905  *                          Use RTSTR_MAX to translate the entire string.
    906  * @param   ppsz            If cch is non-zero, this must either be pointing to pointer to
    907  *                          a buffer of the specified size, or pointer to a NULL pointer.
    908  *                          If *ppsz is NULL or cch is zero a buffer of at least cch items
    909  *                          will be allocated to hold the translated string.
    910  *                          If a buffer was requested it must be freed using RTStrFree().
    911  * @param   cch             The buffer size in bytes. This includes the terminator.
     920 * @param   cchString       The maximum size in chars (the type) to convert.
     921 *                          The conversion stop when it reaches cchString or
     922 *                          the string terminator ('\\0'). Use RTSTR_MAX to
     923 *                          translate the entire string.
     924 * @param   ppsz            If cch is non-zero, this must either be pointing to
     925 *                          pointer to a buffer of the specified size, or
     926 *                          pointer to a NULL pointer.  If *ppsz is NULL or cch
     927 *                          is zero a buffer of at least cch items will be
     928 *                          allocated to hold the translated string. If a
     929 *                          buffer was requested it must be freed using
     930 *                          RTStrFree().
     931 * @param   cch             The buffer size in bytes.  This includes the
     932 *                          terminator.
    912933 * @param   pcch            Where to store the length of the translated string,
    913934 *                          excluding the terminator. (Optional)
     
    952973 * @returns iprt status code.
    953974 * @param   pszString       The Latin-1 string to convert.
    954  * @param   cchString       The number of Latin-1 characters to translate from pszString.
    955  *                          The translation will stop when reaching cchString or the terminator ('\\0').
    956  *                          Use RTSTR_MAX to translate the entire string.
    957  * @param   ppsz            If cch is non-zero, this must either be pointing to a pointer to
    958  *                          a buffer of the specified size, or pointer to a NULL pointer.
    959  *                          If *ppsz is NULL or cch is zero a buffer of at least cch chars
    960  *                          will be allocated to hold the translated string.
    961  *                          If a buffer was requested it must be freed using RTStrFree().
     975 * @param   cchString       The number of Latin-1 characters to translate from
     976 *                          pszString. The translation will stop when reaching
     977 *                          cchString or the terminator ('\\0').  Use RTSTR_MAX
     978 *                          to translate the entire string.
     979 * @param   ppsz            If cch is non-zero, this must either be pointing to
     980 *                          a pointer to a buffer of the specified size, or
     981 *                          pointer to a NULL pointer.  If *ppsz is NULL or cch
     982 *                          is zero a buffer of at least cch chars will be
     983 *                          allocated to hold the translated string. If a
     984 *                          buffer was requested it must be freed using
     985 *                          RTStrFree().
    962986 * @param   cch             The buffer size in chars (the type). This includes the terminator.
    963987 * @param   pcch            Where to store the length of the translated string,
     
    9781002 * @returns iprt status code.
    9791003 * @param   pszString       The Latin1 string to convert.
    980  * @param   cchString       The number of Latin1 characters to translate from pwszString.
    981  *                          The translation will stop when reaching cchString or the terminator ('\\0').
    982  *                          Use RTSTR_MAX to translate the entire string.
    983  * @param   ppsz            If cch is non-zero, this must either be pointing to a pointer to
    984  *                          a buffer of the specified size, or pointer to a NULL pointer.
    985  *                          If *ppsz is NULL or cch is zero a buffer of at least cch chars
    986  *                          will be allocated to hold the translated string.
    987  *                          If a buffer was requested it must be freed using RTStrFree().
    988  * @param   cch             The buffer size in chars (the type). This includes the terminator.
     1004 * @param   cchString       The number of Latin1 characters to translate from
     1005 *                          pwszString.  The translation will stop when
     1006 *                          reaching cchString or the terminator ('\\0').  Use
     1007 *                          RTSTR_MAX to translate the entire string.
     1008 * @param   ppsz            If cch is non-zero, this must either be pointing to
     1009 *                          a pointer to a buffer of the specified size, or
     1010 *                          pointer to a NULL pointer.  If *ppsz is NULL or cch
     1011 *                          is zero a buffer of at least cch chars will be
     1012 *                          allocated to hold the translated string.  If a
     1013 *                          buffer was requested it must be freed using
     1014 *                          RTStrFree().
     1015 * @param   cch             The buffer size in chars (the type).  This includes
     1016 *                          the terminator.
    9891017 * @param   pcch            Where to store the length of the translated string,
    9901018 *                          excluding the terminator. (Optional)
     
    10051033 * RTLatin1ToUtf8Ex() should be used.
    10061034 *
    1007  * @returns Number of char (bytes).
     1035 * @returns Number of chars (bytes).
    10081036 * @returns 0 if the string was incorrectly encoded.
    10091037 * @param   psz        The Latin-1 string.
     
    10171045 * @param   psz         The string.
    10181046 * @param   cch         The max string length. Use RTSTR_MAX to process the entire string.
    1019  * @param   pcch        Where to store the string length (in bytes). Optional.
     1047 * @param   pcch        Where to store the string length (in bytes).  Optional.
    10201048 *                      This is undefined on failure.
    10211049 */
     
    11591187
    11601188/**
    1161  * Get the UTF-8 size in characters of a given Unicode code point.  The code
    1162  * point is expected to be a valid Unicode one, but not necessarily in the
    1163  * range supported by UTF-8.
    1164  *
    1165  * @returns the size in characters, or zero if there is no UTF-8 encoding
     1189 * Get the UTF-8 size in characters of a given Unicode code point.
     1190 *
     1191 * The code point is expected to be a valid Unicode one, but not necessarily in
     1192 * the range supported by UTF-8.
     1193 *
     1194 * @returns The number of chars (bytes) required to encode the code point, or
     1195 *          zero if there is no UTF-8 encoding.
     1196 * @param   CodePoint       The unicode code point.
    11661197 */
    11671198DECLINLINE(size_t) RTStrCpSize(RTUNICP CodePoint)
    11681199{
    1169     if (CodePoint < 0x80)
     1200    if (CodePoint < 0x00000080)
    11701201        return 1;
    1171     if (CodePoint < 0x800)
     1202    if (CodePoint < 0x00000800)
    11721203        return 2;
    1173     if (CodePoint < 0x10000)
     1204    if (CodePoint < 0x00010000)
    11741205        return 3;
    1175     if (CodePoint < 0x11000)
     1206#ifdef RT_USE_RTC_3629
     1207    if (CodePoint < 0x00011000)
    11761208        return 4;
     1209#else
     1210    if (CodePoint < 0x00200000)
     1211        return 4;
     1212    if (CodePoint < 0x04000000)
     1213        return 5;
     1214    if (CodePoint < 0x7fffffff)
     1215        return 6;
     1216#endif
    11771217    return 0;
    11781218}
     
    12931333
    12941334/**
    1295  * Get the Latin-1 size in characters of a given Unicode code point.  The code
    1296  * point is expected to be a valid Unicode one, but not necessarily in the
    1297  * range supported by Latin-1.
     1335 * Get the Latin-1 size in characters of a given Unicode code point.
     1336 *
     1337 * The code point is expected to be a valid Unicode one, but not necessarily in
     1338 * the range supported by Latin-1.
    12981339 *
    12991340 * @returns the size in characters, or zero if there is no Latin-1 encoding
  • trunk/include/iprt/types.h

    r31155 r31418  
    15751575 * Unicode Code Point.
    15761576 */
    1577 typedef uint32_t        RTUNICP;
     1577typedef uint32_t            RTUNICP;
    15781578/** Pointer to an Unicode Code Point. */
    1579 typedef RTUNICP        *PRTUNICP;
     1579typedef RTUNICP            *PRTUNICP;
    15801580/** Pointer to an Unicode Code Point. */
    1581 typedef const RTUNICP  *PCRTUNICP;
     1581typedef const RTUNICP      *PCRTUNICP;
     1582/** Max value a RTUNICP type can hold. */
     1583#define RTUNICP_MAX         ( ~(RTUNICP)0 )
     1584/** Invalid code point.
     1585 * This is returned when encountered invalid encodings or invalid
     1586 * unicode code points. */
     1587#define RTUNICP_INVALID     ( UINT32_C(0xfffffffe) )
    15821588
    15831589
  • trunk/include/iprt/uni.h

    r28878 r31418  
    4545
    4646RT_C_DECLS_BEGIN
    47 
    48 
    49 /** Max value a RTUNICP type can hold. */
    50 #define RTUNICP_MAX         ( ~(RTUNICP)0 )
    51 
    52 /** Invalid code point.
    53  * This is returned when encountered invalid encodings or invalid
    54  * unicode code points. */
    55 #define RTUNICP_INVALID     ( 0xfffffffe )
    5647
    5748
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