ustr.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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) 1998-2012, International Business Machines
  7. * Corporation and others. All Rights Reserved.
  8. *
  9. *******************************************************************************
  10. *
  11. * File ustr.h
  12. *
  13. * Modification History:
  14. *
  15. * Date Name Description
  16. * 05/28/99 stephen Creation.
  17. *******************************************************************************
  18. */
  19. #ifndef USTR_H
  20. #define USTR_H 1
  21. #include "unicode/utypes.h"
  22. #define U_APPEND_CHAR32(c,target,len) UPRV_BLOCK_MACRO_BEGIN { \
  23. if (c <= 0xffff) \
  24. { \
  25. *(target)++ = (UChar) c; \
  26. len=1; \
  27. } \
  28. else \
  29. { \
  30. target[0] = U16_LEAD(c); \
  31. target[1] = U16_TRAIL(c); \
  32. len=2; \
  33. target +=2; \
  34. } \
  35. } UPRV_BLOCK_MACRO_END
  36. #define U_APPEND_CHAR32_ONLY(c,target) UPRV_BLOCK_MACRO_BEGIN { \
  37. if (c <= 0xffff) \
  38. { \
  39. *(target)++ = (UChar) c; \
  40. } \
  41. else \
  42. { \
  43. target[0] = U16_LEAD(c); \
  44. target[1] = U16_TRAIL(c); \
  45. target +=2; \
  46. } \
  47. } UPRV_BLOCK_MACRO_END
  48. /* A C representation of a string "object" (to avoid realloc all the time) */
  49. struct UString {
  50. UChar *fChars;
  51. int32_t fLength;
  52. int32_t fCapacity;
  53. };
  54. U_CFUNC void ustr_init(struct UString *s);
  55. U_CFUNC void
  56. ustr_initChars(struct UString *s, const char* source, int32_t length, UErrorCode *status);
  57. U_CFUNC void ustr_deinit(struct UString *s);
  58. U_CFUNC void ustr_setlen(struct UString *s, int32_t len, UErrorCode *status);
  59. U_CFUNC void ustr_cpy(struct UString *dst, const struct UString *src,
  60. UErrorCode *status);
  61. U_CFUNC void ustr_cat(struct UString *dst, const struct UString *src,
  62. UErrorCode *status);
  63. U_CFUNC void ustr_ncat(struct UString *dst, const struct UString *src,
  64. int32_t n, UErrorCode *status);
  65. U_CFUNC void ustr_ucat(struct UString *dst, UChar c, UErrorCode *status);
  66. U_CFUNC void ustr_u32cat(struct UString *dst, UChar32 c, UErrorCode *status);
  67. U_CFUNC void ustr_uscat(struct UString *dst, const UChar* src,int len,UErrorCode *status);
  68. #endif