cpputils.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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-2011, International Business Machines
  7. * Corporation and others. All Rights Reserved.
  8. *
  9. ******************************************************************************
  10. * file name: cpputils.h
  11. * encoding: UTF-8
  12. * tab size: 8 (not used)
  13. * indentation:4
  14. */
  15. #ifndef CPPUTILS_H
  16. #define CPPUTILS_H
  17. #include "unicode/utypes.h"
  18. #include "unicode/unistr.h"
  19. #include "cmemory.h"
  20. /*==========================================================================*/
  21. /* Array copy utility functions */
  22. /*==========================================================================*/
  23. static
  24. inline void uprv_arrayCopy(const double* src, double* dst, int32_t count)
  25. { uprv_memcpy(dst, src, (size_t)count * sizeof(*src)); }
  26. static
  27. inline void uprv_arrayCopy(const double* src, int32_t srcStart,
  28. double* dst, int32_t dstStart, int32_t count)
  29. { uprv_memcpy(dst+dstStart, src+srcStart, (size_t)count * sizeof(*src)); }
  30. static
  31. inline void uprv_arrayCopy(const int8_t* src, int8_t* dst, int32_t count)
  32. { uprv_memcpy(dst, src, (size_t)count * sizeof(*src)); }
  33. static
  34. inline void uprv_arrayCopy(const int8_t* src, int32_t srcStart,
  35. int8_t* dst, int32_t dstStart, int32_t count)
  36. { uprv_memcpy(dst+dstStart, src+srcStart, (size_t)count * sizeof(*src)); }
  37. static
  38. inline void uprv_arrayCopy(const int16_t* src, int16_t* dst, int32_t count)
  39. { uprv_memcpy(dst, src, (size_t)count * sizeof(*src)); }
  40. static
  41. inline void uprv_arrayCopy(const int16_t* src, int32_t srcStart,
  42. int16_t* dst, int32_t dstStart, int32_t count)
  43. { uprv_memcpy(dst+dstStart, src+srcStart, (size_t)count * sizeof(*src)); }
  44. static
  45. inline void uprv_arrayCopy(const int32_t* src, int32_t* dst, int32_t count)
  46. { uprv_memcpy(dst, src, (size_t)count * sizeof(*src)); }
  47. static
  48. inline void uprv_arrayCopy(const int32_t* src, int32_t srcStart,
  49. int32_t* dst, int32_t dstStart, int32_t count)
  50. { uprv_memcpy(dst+dstStart, src+srcStart, (size_t)count * sizeof(*src)); }
  51. static
  52. inline void
  53. uprv_arrayCopy(const UChar *src, int32_t srcStart,
  54. UChar *dst, int32_t dstStart, int32_t count)
  55. { uprv_memcpy(dst+dstStart, src+srcStart, (size_t)count * sizeof(*src)); }
  56. /**
  57. * Copy an array of UnicodeString OBJECTS (not pointers).
  58. * @internal
  59. */
  60. static inline void
  61. uprv_arrayCopy(const icu::UnicodeString *src, icu::UnicodeString *dst, int32_t count)
  62. { while(count-- > 0) *dst++ = *src++; }
  63. /**
  64. * Copy an array of UnicodeString OBJECTS (not pointers).
  65. * @internal
  66. */
  67. static inline void
  68. uprv_arrayCopy(const icu::UnicodeString *src, int32_t srcStart,
  69. icu::UnicodeString *dst, int32_t dstStart, int32_t count)
  70. { uprv_arrayCopy(src+srcStart, dst+dstStart, count); }
  71. /**
  72. * Checks that the string is readable and writable.
  73. * Sets U_ILLEGAL_ARGUMENT_ERROR if the string isBogus() or has an open getBuffer().
  74. */
  75. inline void
  76. uprv_checkCanGetBuffer(const icu::UnicodeString &s, UErrorCode &errorCode) {
  77. if(U_SUCCESS(errorCode) && s.isBogus()) {
  78. errorCode=U_ILLEGAL_ARGUMENT_ERROR;
  79. }
  80. }
  81. #endif /* _CPPUTILS */