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
27static
28inline void uprv_arrayCopy(const double* src, double* dst, int32_t count)
29{ uprv_memcpy(dst, src, (size_t)count * sizeof(*src)); }
30
31static
32inline 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
36static
37inline void uprv_arrayCopy(const int8_t* src, int8_t* dst, int32_t count)
38 { uprv_memcpy(dst, src, (size_t)count * sizeof(*src)); }
39
40static
41inline 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
45static
46inline void uprv_arrayCopy(const int16_t* src, int16_t* dst, int32_t count)
47{ uprv_memcpy(dst, src, (size_t)count * sizeof(*src)); }
48
49static
50inline 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
54static
55inline void uprv_arrayCopy(const int32_t* src, int32_t* dst, int32_t count)
56{ uprv_memcpy(dst, src, (size_t)count * sizeof(*src)); }
57
58static
59inline 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
63static
64inline void
65uprv_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 */
73static inline void
74uprv_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 */
81static inline void
82uprv_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 */
90inline void
91uprv_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