cstring.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. ******************************************************************************
  5. *
  6. * Copyright (C) 1997-2012, International Business Machines
  7. * Corporation and others. All Rights Reserved.
  8. *
  9. ******************************************************************************
  10. *
  11. * File CSTRING.H
  12. *
  13. * Contains CString interface
  14. *
  15. * @author Helena Shih
  16. *
  17. * Modification History:
  18. *
  19. * Date Name Description
  20. * 6/17/98 hshih Created.
  21. * 05/03/99 stephen Changed from functions to macros.
  22. * 06/14/99 stephen Added icu_strncat, icu_strncmp, icu_tolower
  23. *
  24. ******************************************************************************
  25. */
  26. #ifndef CSTRING_H
  27. #define CSTRING_H 1
  28. #include "unicode/utypes.h"
  29. #include "cmemory.h"
  30. #include <string.h>
  31. #include <stdlib.h>
  32. #include <ctype.h>
  33. #define uprv_strcpy(dst, src) U_STANDARD_CPP_NAMESPACE strcpy(dst, src)
  34. #define uprv_strlen(str) U_STANDARD_CPP_NAMESPACE strlen(str)
  35. #define uprv_strcmp(s1, s2) U_STANDARD_CPP_NAMESPACE strcmp(s1, s2)
  36. #define uprv_strcat(dst, src) U_STANDARD_CPP_NAMESPACE strcat(dst, src)
  37. #define uprv_strchr(s, c) U_STANDARD_CPP_NAMESPACE strchr(s, c)
  38. #define uprv_strstr(s, c) U_STANDARD_CPP_NAMESPACE strstr(s, c)
  39. #define uprv_strrchr(s, c) U_STANDARD_CPP_NAMESPACE strrchr(s, c)
  40. #define uprv_strncpy(dst, src, size) U_STANDARD_CPP_NAMESPACE strncpy(dst, src, size)
  41. #define uprv_strncmp(s1, s2, n) U_STANDARD_CPP_NAMESPACE strncmp(s1, s2, n)
  42. #define uprv_strncat(dst, src, n) U_STANDARD_CPP_NAMESPACE strncat(dst, src, n)
  43. /**
  44. * Is c an ASCII-repertoire letter a-z or A-Z?
  45. * Note: The implementation is specific to whether ICU is compiled for
  46. * an ASCII-based or EBCDIC-based machine. There just does not seem to be a better name for this.
  47. */
  48. U_CAPI UBool U_EXPORT2
  49. uprv_isASCIILetter(char c);
  50. // NOTE: For u_asciiToUpper that takes a UChar, see ustr_imp.h
  51. U_CAPI char U_EXPORT2
  52. uprv_toupper(char c);
  53. U_CAPI char U_EXPORT2
  54. uprv_asciitolower(char c);
  55. U_CAPI char U_EXPORT2
  56. uprv_ebcdictolower(char c);
  57. #if U_CHARSET_FAMILY==U_ASCII_FAMILY
  58. # define uprv_tolower uprv_asciitolower
  59. #elif U_CHARSET_FAMILY==U_EBCDIC_FAMILY
  60. # define uprv_tolower uprv_ebcdictolower
  61. #else
  62. # error U_CHARSET_FAMILY is not valid
  63. #endif
  64. #define uprv_strtod(source, end) U_STANDARD_CPP_NAMESPACE strtod(source, end)
  65. #define uprv_strtoul(str, end, base) U_STANDARD_CPP_NAMESPACE strtoul(str, end, base)
  66. #define uprv_strtol(str, end, base) U_STANDARD_CPP_NAMESPACE strtol(str, end, base)
  67. /* Conversion from a digit to the character with radix base from 2-19 */
  68. /* May need to use U_UPPER_ORDINAL*/
  69. #define T_CString_itosOffset(a) ((a)<=9?('0'+(a)):('A'+(a)-10))
  70. U_CAPI char* U_EXPORT2
  71. uprv_strdup(const char *src);
  72. /**
  73. * uprv_malloc n+1 bytes, and copy n bytes from src into the new string.
  74. * Terminate with a null at offset n. If n is -1, works like uprv_strdup
  75. * @param src
  76. * @param n length of the input string, not including null.
  77. * @return new string (owned by caller, use uprv_free to free).
  78. * @internal
  79. */
  80. U_CAPI char* U_EXPORT2
  81. uprv_strndup(const char *src, int32_t n);
  82. U_CAPI char* U_EXPORT2
  83. T_CString_toLowerCase(char* str);
  84. U_CAPI char* U_EXPORT2
  85. T_CString_toUpperCase(char* str);
  86. U_CAPI int32_t U_EXPORT2
  87. T_CString_integerToString(char *buffer, int32_t n, int32_t radix);
  88. U_CAPI int32_t U_EXPORT2
  89. T_CString_int64ToString(char *buffer, int64_t n, uint32_t radix);
  90. U_CAPI int32_t U_EXPORT2
  91. T_CString_stringToInteger(const char *integerString, int32_t radix);
  92. /**
  93. * Case-insensitive, language-independent string comparison
  94. * limited to the ASCII character repertoire.
  95. */
  96. U_CAPI int U_EXPORT2
  97. uprv_stricmp(const char *str1, const char *str2);
  98. /**
  99. * Case-insensitive, language-independent string comparison
  100. * limited to the ASCII character repertoire.
  101. */
  102. U_CAPI int U_EXPORT2
  103. uprv_strnicmp(const char *str1, const char *str2, uint32_t n);
  104. #endif /* ! CSTRING_H */