]> git.saurik.com Git - apple/icu.git/blame - icuSources/common/cpputils.h
ICU-66108.tar.gz
[apple/icu.git] / icuSources / common / cpputils.h
CommitLineData
f3c0d7a5
A
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
b75a7d8f
A
3/*
4******************************************************************************
5*
4388f060 6* Copyright (C) 1997-2011, International Business Machines
b75a7d8f
A
7* Corporation and others. All Rights Reserved.
8*
9******************************************************************************
10* file name: cpputils.h
f3c0d7a5 11* encoding: UTF-8
b75a7d8f
A
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"
73c04bcf 20#include "unicode/unistr.h"
b75a7d8f
A
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)
a62d09fc 29{ uprv_memcpy(dst, src, (size_t)count * sizeof(*src)); }
b75a7d8f
A
30
31static
32inline void uprv_arrayCopy(const double* src, int32_t srcStart,
33 double* dst, int32_t dstStart, int32_t count)
a62d09fc 34{ uprv_memcpy(dst+dstStart, src+srcStart, (size_t)count * sizeof(*src)); }
b75a7d8f
A
35
36static
37inline void uprv_arrayCopy(const int8_t* src, int8_t* dst, int32_t count)
a62d09fc 38 { uprv_memcpy(dst, src, (size_t)count * sizeof(*src)); }
b75a7d8f
A
39
40static
41inline void uprv_arrayCopy(const int8_t* src, int32_t srcStart,
42 int8_t* dst, int32_t dstStart, int32_t count)
a62d09fc 43{ uprv_memcpy(dst+dstStart, src+srcStart, (size_t)count * sizeof(*src)); }
b75a7d8f
A
44
45static
46inline void uprv_arrayCopy(const int16_t* src, int16_t* dst, int32_t count)
a62d09fc 47{ uprv_memcpy(dst, src, (size_t)count * sizeof(*src)); }
b75a7d8f
A
48
49static
50inline void uprv_arrayCopy(const int16_t* src, int32_t srcStart,
51 int16_t* dst, int32_t dstStart, int32_t count)
a62d09fc 52{ uprv_memcpy(dst+dstStart, src+srcStart, (size_t)count * sizeof(*src)); }
b75a7d8f
A
53
54static
55inline void uprv_arrayCopy(const int32_t* src, int32_t* dst, int32_t count)
a62d09fc 56{ uprv_memcpy(dst, src, (size_t)count * sizeof(*src)); }
b75a7d8f
A
57
58static
59inline void uprv_arrayCopy(const int32_t* src, int32_t srcStart,
60 int32_t* dst, int32_t dstStart, int32_t count)
a62d09fc 61{ uprv_memcpy(dst+dstStart, src+srcStart, (size_t)count * sizeof(*src)); }
b75a7d8f
A
62
63static
64inline void
65uprv_arrayCopy(const UChar *src, int32_t srcStart,
66 UChar *dst, int32_t dstStart, int32_t count)
a62d09fc 67{ uprv_memcpy(dst+dstStart, src+srcStart, (size_t)count * sizeof(*src)); }
b75a7d8f 68
73c04bcf
A
69/**
70 * Copy an array of UnicodeString OBJECTS (not pointers).
71 * @internal
72 */
73static inline void
4388f060 74uprv_arrayCopy(const icu::UnicodeString *src, icu::UnicodeString *dst, int32_t count)
73c04bcf
A
75{ while(count-- > 0) *dst++ = *src++; }
76
77/**
78 * Copy an array of UnicodeString OBJECTS (not pointers).
79 * @internal
80 */
81static inline void
4388f060
A
82uprv_arrayCopy(const icu::UnicodeString *src, int32_t srcStart,
83 icu::UnicodeString *dst, int32_t dstStart, int32_t count)
73c04bcf
A
84{ uprv_arrayCopy(src+srcStart, dst+dstStart, count); }
85
729e4ab9
A
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
4388f060 91uprv_checkCanGetBuffer(const icu::UnicodeString &s, UErrorCode &errorCode) {
729e4ab9
A
92 if(U_SUCCESS(errorCode) && s.isBogus()) {
93 errorCode=U_ILLEGAL_ARGUMENT_ERROR;
94 }
95}
96
b75a7d8f 97#endif /* _CPPUTILS */