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 16 #ifndef CPPUTILS_H 17 #define CPPUTILS_H 18 19 #include "unicode/utypes.h" 20 #include "unicode/unistr.h" 21 #include "cmemory.h" 22 23 /*==========================================================================*/ 24 /* Array copy utility functions */ 25 /*==========================================================================*/ 26 27 static uprv_arrayCopy(const double * src,double * dst,int32_t count)28 inline void uprv_arrayCopy(const double* src, double* dst, int32_t count) 29 { uprv_memcpy(dst, src, (size_t)count * sizeof(*src)); } 30 31 static uprv_arrayCopy(const double * src,int32_t srcStart,double * dst,int32_t dstStart,int32_t count)32 inline void uprv_arrayCopy(const double* src, int32_t srcStart, 33 double* dst, int32_t dstStart, int32_t count) 34 { uprv_memcpy(dst+dstStart, src+srcStart, (size_t)count * sizeof(*src)); } 35 36 static uprv_arrayCopy(const int8_t * src,int8_t * dst,int32_t count)37 inline void uprv_arrayCopy(const int8_t* src, int8_t* dst, int32_t count) 38 { uprv_memcpy(dst, src, (size_t)count * sizeof(*src)); } 39 40 static uprv_arrayCopy(const int8_t * src,int32_t srcStart,int8_t * dst,int32_t dstStart,int32_t count)41 inline void uprv_arrayCopy(const int8_t* src, int32_t srcStart, 42 int8_t* dst, int32_t dstStart, int32_t count) 43 { uprv_memcpy(dst+dstStart, src+srcStart, (size_t)count * sizeof(*src)); } 44 45 static uprv_arrayCopy(const int16_t * src,int16_t * dst,int32_t count)46 inline void uprv_arrayCopy(const int16_t* src, int16_t* dst, int32_t count) 47 { uprv_memcpy(dst, src, (size_t)count * sizeof(*src)); } 48 49 static uprv_arrayCopy(const int16_t * src,int32_t srcStart,int16_t * dst,int32_t dstStart,int32_t count)50 inline void uprv_arrayCopy(const int16_t* src, int32_t srcStart, 51 int16_t* dst, int32_t dstStart, int32_t count) 52 { uprv_memcpy(dst+dstStart, src+srcStart, (size_t)count * sizeof(*src)); } 53 54 static uprv_arrayCopy(const int32_t * src,int32_t * dst,int32_t count)55 inline void uprv_arrayCopy(const int32_t* src, int32_t* dst, int32_t count) 56 { uprv_memcpy(dst, src, (size_t)count * sizeof(*src)); } 57 58 static uprv_arrayCopy(const int32_t * src,int32_t srcStart,int32_t * dst,int32_t dstStart,int32_t count)59 inline void uprv_arrayCopy(const int32_t* src, int32_t srcStart, 60 int32_t* dst, int32_t dstStart, int32_t count) 61 { uprv_memcpy(dst+dstStart, src+srcStart, (size_t)count * sizeof(*src)); } 62 63 static 64 inline void uprv_arrayCopy(const UChar * src,int32_t srcStart,UChar * dst,int32_t dstStart,int32_t count)65 uprv_arrayCopy(const UChar *src, int32_t srcStart, 66 UChar *dst, int32_t dstStart, int32_t count) 67 { uprv_memcpy(dst+dstStart, src+srcStart, (size_t)count * sizeof(*src)); } 68 69 /** 70 * Copy an array of UnicodeString OBJECTS (not pointers). 71 * @internal 72 */ 73 static inline void uprv_arrayCopy(const icu::UnicodeString * src,icu::UnicodeString * dst,int32_t count)74 uprv_arrayCopy(const icu::UnicodeString *src, icu::UnicodeString *dst, int32_t count) 75 { while(count-- > 0) *dst++ = *src++; } 76 77 /** 78 * Copy an array of UnicodeString OBJECTS (not pointers). 79 * @internal 80 */ 81 static inline void uprv_arrayCopy(const icu::UnicodeString * src,int32_t srcStart,icu::UnicodeString * dst,int32_t dstStart,int32_t count)82 uprv_arrayCopy(const icu::UnicodeString *src, int32_t srcStart, 83 icu::UnicodeString *dst, int32_t dstStart, int32_t count) 84 { uprv_arrayCopy(src+srcStart, dst+dstStart, count); } 85 86 /** 87 * Checks that the string is readable and writable. 88 * Sets U_ILLEGAL_ARGUMENT_ERROR if the string isBogus() or has an open getBuffer(). 89 */ 90 inline void uprv_checkCanGetBuffer(const icu::UnicodeString & s,UErrorCode & errorCode)91 uprv_checkCanGetBuffer(const icu::UnicodeString &s, UErrorCode &errorCode) { 92 if(U_SUCCESS(errorCode) && s.isBogus()) { 93 errorCode=U_ILLEGAL_ARGUMENT_ERROR; 94 } 95 } 96 97 #endif /* _CPPUTILS */ 98