xsstringarray.h
Go to the documentation of this file.
1 
2 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions, and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions, and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 //
15 // 3. Neither the names of the copyright holders nor the names of their contributors
16 // may be used to endorse or promote products derived from this software without
17 // specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
26 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
28 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
29 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
30 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
31 //
32 
33 
34 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
35 // All rights reserved.
36 //
37 // Redistribution and use in source and binary forms, with or without modification,
38 // are permitted provided that the following conditions are met:
39 //
40 // 1. Redistributions of source code must retain the above copyright notice,
41 // this list of conditions, and the following disclaimer.
42 //
43 // 2. Redistributions in binary form must reproduce the above copyright notice,
44 // this list of conditions, and the following disclaimer in the documentation
45 // and/or other materials provided with the distribution.
46 //
47 // 3. Neither the names of the copyright holders nor the names of their contributors
48 // may be used to endorse or promote products derived from this software without
49 // specific prior written permission.
50 //
51 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
52 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
53 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
54 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
56 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
58 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
59 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
60 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
61 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
62 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
63 //
64 
65 #ifndef XSSTRINGARRAY_H
66 #define XSSTRINGARRAY_H
67 
68 #include "xsarray.h"
69 
70 #ifdef __cplusplus
71 #include "xsstring.h"
72 extern "C" {
73 #endif
74 
76 
77 #ifndef __cplusplus
78 #define XSSTRINGARRAY_INITIALIZER XSARRAY_INITIALIZER(&g_xsStringArrayDescriptor)
79 struct XsString;
80 
83 
84 XSTYPES_DLL_API void XsStringArray_construct(XsStringArray* thisPtr, XsSize count, struct XsString const* src);
85 #define XsStringArray_destruct(thisPtr) XsArray_destruct(thisPtr)
86 #endif
87 XSTYPES_DLL_API void XsStringArray_fromSplicedString(struct XsStringArray* thisPtr, struct XsString const* src, struct XsString const* separators);
88 XSTYPES_DLL_API void XsStringArray_join(struct XsStringArray const* thisPtr, struct XsString* result, struct XsString const* separator);
89 
90 #ifdef __cplusplus
91 } // extern "C"
92 
93 struct XsStringArray : public XsArrayImpl<XsString, g_xsStringArrayDescriptor, XsStringArray>
94 {
96  inline explicit XsStringArray(XsSize sz = 0, XsString const* src = 0)
97  : ArrayImpl(sz, src)
98  {
99  }
100 
102  inline XsStringArray(XsStringArray const& other)
103  : ArrayImpl(other)
104  {
105  }
106 
108  inline explicit XsStringArray(XsString* ref, XsSize sz, XsDataFlags flags /* = XSDF_None */)
109  : ArrayImpl(ref, sz, flags)
110  {
111  }
112 
113 #ifndef SWIG
114 
115  friend void swap(XsStringArray& first, XsStringArray& second)
116  {
117  first.swap(second);
118  }
119 #endif
120 
121 #ifndef XSENS_NOITERATOR
122  template <typename Iterator>
124  inline XsStringArray(Iterator beginIt, Iterator endIt)
125  : ArrayImpl(beginIt, endIt)
126  {
127  }
128 #endif
129 
134  XsString join(XsString const& separator) const
135  {
136  XsString tmp;
137  XsStringArray_join(this, &tmp, &separator);
138  return tmp;
139  }
140 
142  void fromSplicedString(XsString const& src, XsString const& separators)
143  {
144  XsStringArray_fromSplicedString(this, &src, &separators);
145  }
146 
148  inline explicit XsStringArray(XsString const& src, XsString const& separators)
149  : ArrayImpl()
150  {
151  XsStringArray_fromSplicedString(this, &src, &separators);
152  }
153 
159  ptrdiff_t find(XsString const& needle, bool isCaseSensitive = true) const
160  {
161  if (isCaseSensitive)
162  return XsArrayImpl<XsString, g_xsStringArrayDescriptor, XsStringArray>::find(needle);
163 
164  if (size() == 0)
165  return -1;
166 
167  XsString needleLower(needle);
168  for (XsString::iterator c = needleLower.begin(); c != needleLower.end(); ++c)
169  *c = tolower(*c);
170 
171  for (XsSize i = 0; i < size(); ++i) // loop over all elements of the lists
172  {
173  XsString const& a = at(i);
174  if (a.size() != needleLower.size())
175  continue;
176 
177  bool found = true;
178  for (XsSize j = 0; j < a.size(); ++j)
179  {
180  if (tolower(a[j]) != needleLower[j])
181  {
182  found = false;
183  break;
184  }
185  }
186 
187  if (found)
188  return (int)i;
189  }
190  return -1;
191  }
192 };
193 #endif
194 
195 #endif
XsArrayDescriptor
This object describes how to treat the data in an array.
Definition: xsarray.h:103
xsstring.h
XSARRAY_STRUCT
XSARRAY_STRUCT(XsStringArray, struct XsString)
XsStringArray
A list of XsString values.
XsStringArray::XsStringArray_fromSplicedString
void XsStringArray_fromSplicedString(struct XsStringArray *thisPtr, struct XsString const *src, struct XsString const *separators)
Splice the supplied string and put the resulting substrings in the string array.
Definition: xsstringarray.c:102
g_xsStringArrayDescriptor
const XsArrayDescriptor XSTYPES_DLL_API g_xsStringArrayDescriptor
Descriptor for XsStringArray.
Definition: xsstringarray.c:74
XsSize
size_t XsSize
XsSize must be unsigned number!
Definition: xstypedefs.h:74
xsarray.h
XsStringArray_construct
XSTYPES_DLL_API void XsStringArray_construct(XsStringArray *thisPtr, XsSize count, struct XsString const *src)
XSTYPES_DLL_API
#define XSTYPES_DLL_API
Definition: xstypesconfig.h:65
XsStringArray
struct XsStringArray XsStringArray
Definition: xsstringarray.h:82
XsDataFlags
XsDataFlags
These flags define the behaviour of data contained by Xsens data structures.
Definition: xstypedefs.h:107
XsStringArray::XsStringArray_join
void XsStringArray_join(struct XsStringArray const *thisPtr, struct XsString *result, struct XsString const *separator)
Join the string array into a single string, inserting separator between substrings.
Definition: xsstringarray.c:145
XsString
A 0-terminated managed string of characters.


xsens_mti_driver
Author(s):
autogenerated on Sun Sep 3 2023 02:43:20