StringHelper.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2011, SRI International (R)
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #pragma once
19 
20 #ifndef __OpenKarto_StringHelper_h__
21 #define __OpenKarto_StringHelper_h__
22 
23 #include <stdio.h>
24 #include <ostream>
25 #include <sstream>
26 
27 #include <OpenKarto/String.h>
28 
29 namespace karto
30 {
31 
33 
34 
38 
39  class Color;
40 
41  class Pose2;
42  class Pose3;
43  class Quaternion;
44 
45  template<typename T> class Size2;
46 
47  template<typename T> class Vector2;
48  template<typename T> class Vector3;
49  template<typename T> class Vector4;
50 
55  {
56  public:
62  static String ToString(const char* value);
63 
69  static String ToString(kt_bool value);
70 
76  static String ToString(kt_int16s value);
77 
83  static String ToString(kt_int16u value);
84 
90  static String ToString(kt_int32s value);
91 
97  static String ToString(kt_int32u value);
98 
104  static String ToString(kt_int64s value);
105 
111  static String ToString(kt_int64u value);
112 
113 #if defined(__APPLE__) && !defined(__LP64__)
114  static String ToString(kt_size_t value);
115 #endif
116 
122  static String ToString(kt_float value);
123 
129  static String ToString(kt_double value);
130 
137  static String ToString(kt_float value, kt_int32u precision);
138 
145  static String ToString(kt_double value, kt_int32u precision);
146 
152  static String ToString(const String& rValue);
153 
159  template<typename T>
160  inline static String ToString(const Size2<T>& rValue);
161 
167  template<typename T>
168  inline static String ToString(const Vector2<T>& rValue);
169 
175  template<typename T>
176  inline static String ToString(const Vector3<T>& rValue);
177 
183  template<typename T>
184  inline static String ToString(const Vector4<T>& rValue);
185 
191  static String ToString(const Quaternion& rValue);
192 
198  static String ToString(const Color& rValue);
199 
205  static String ToString(const Pose2& rValue);
206 
212  static String ToString(const Pose3& rValue);
213 
220  static kt_bool FromString(const String& rStringValue, kt_bool& rValue);
221 
228  static kt_bool FromString(const String& rStringValue, kt_int16s& rValue);
229 
236  static kt_bool FromString(const String& rStringValue, kt_int16u& rValue);
237 
244  static kt_bool FromString(const String& rStringValue, kt_int32s& rValue);
245 
252  static kt_bool FromString(const String& rStringValue, kt_int32u& rValue);
253 
260  static kt_bool FromString(const String& rStringValue, kt_int64s& rValue);
261 
268  static kt_bool FromString(const String& rStringValue, kt_int64u& rValue);
269 
276  static kt_bool FromString(const String& rStringValue, kt_float& rValue);
277 
284  static kt_bool FromString(const String& rStringValue, kt_double& rValue);
285 
292  static kt_bool FromString(const String& rStringValue, String& rValue);
293 
300  template<typename T>
301  static kt_bool FromString(const String& rStringValue, Size2<T>& rValue)
302  {
303  kt_size_t index = rStringValue.FindFirstOf(" ");
304  if (index != -1)
305  {
306  karto::String stringValue;
307  T value;
308 
309  stringValue = rStringValue.SubString(0, index);
310 
311  value = 0;
312  FromString(stringValue, value);
313  rValue.SetWidth(value);
314 
315  stringValue = rStringValue.SubString(index + 1, rStringValue.Size());
316 
317  value = 0;
318  FromString(stringValue, value);
319  rValue.SetHeight(value);
320 
321  return true;
322  }
323 
324  return false;
325  }
326 
333  template<typename T>
334  static kt_bool FromString(const String& rStringValue, Vector2<T>& rValue)
335  {
336  kt_size_t index = rStringValue.FindFirstOf(" ");
337  if (index != -1)
338  {
339  karto::String stringValue;
340  T value;
341 
342  stringValue = rStringValue.SubString(0, index);
343 
344  value = 0;
345  FromString(stringValue, value);
346  rValue.SetX(value);
347 
348  stringValue = rStringValue.SubString(index + 1, rStringValue.Size());
349 
350  value = 0;
351  FromString(stringValue, value);
352  rValue.SetY(value);
353 
354  return true;
355  }
356 
357  return false;
358  }
359 
366  template<typename T>
367  inline static kt_bool FromString(const String& rStringValue, Vector3<T>& rValue)
368  {
369  karto::String tempString = rStringValue;
370  kt_size_t index = tempString.FindFirstOf(" ");
371  if (index != -1)
372  {
373  karto::String stringValue;
374  T value;
375 
376  // Get X
377  stringValue = tempString.SubString(0, index);
378 
379  value = 0;
380  FromString(stringValue, value);
381  rValue.SetX(value);
382 
383  // Get Y
384  tempString = rStringValue.SubString(index + 1, rStringValue.Size());
385  index = tempString.FindFirstOf(" ");
386 
387  stringValue = tempString.SubString(0, index);
388 
389  value = 0;
390  FromString(stringValue, value);
391  rValue.SetY(value);
392 
393  // Get Z
394  tempString = tempString.SubString(index + 1, rStringValue.Size());
395  index = tempString.FindFirstOf(" ");
396 
397  stringValue = tempString.SubString(index + 1, rStringValue.Size());
398 
399  value = 0;
400  FromString(stringValue, value);
401  rValue.SetZ(value);
402 
403  return true;
404  }
405 
406  return false;
407  }
408 
415  template<typename T>
416  static kt_bool FromString(const String& rStringValue, Vector4<T>& rValue)
417  {
418  karto::String tempString = rStringValue;
419  kt_size_t index = tempString.FindFirstOf(" ");
420  if (index != -1)
421  {
422  karto::String stringValue;
423  T value;
424 
425  // Get X
426  stringValue = tempString.SubString(0, index);
427 
428  value = 0;
429  FromString(stringValue, value);
430  rValue.SetX(value);
431 
432  // Get Y
433  tempString = rStringValue.SubString(index + 1, rStringValue.Size());
434  index = tempString.FindFirstOf(" ");
435 
436  stringValue = tempString.SubString(0, index);
437 
438  value = 0;
439  FromString(stringValue, value);
440  rValue.SetY(value);
441 
442  // Get Z
443  tempString = tempString.SubString(index + 1, rStringValue.Size());
444  index = tempString.FindFirstOf(" ");
445 
446  stringValue = tempString.SubString(index + 1, rStringValue.Size());
447 
448  value = 0;
449  FromString(stringValue, value);
450  rValue.SetZ(value);
451 
452  // Get W
453  tempString = tempString.SubString(index + 1, rStringValue.Size());
454  index = tempString.FindFirstOf(" ");
455 
456  stringValue = tempString.SubString(index + 1, rStringValue.Size());
457 
458  value = 0;
459  FromString(stringValue, value);
460  rValue.SetW(value);
461 
462  return true;
463  }
464 
465  return false;
466  }
467 
474  static kt_bool FromString(const String& rStringValue, Quaternion& rValue);
475 
482  static kt_bool FromString(const String& rStringValue, Color& rValue);
483 
490  static kt_bool FromString(const String& rStringValue, Pose2& rValue);
491 
498  static kt_bool FromString(const String& rStringValue, Pose3& rValue);
499 
505  static String Trim(const String& rValue);
506 
514  static String Replace(const String& rSource, const String& rFind, const String& rReplace);
515 
521  static kt_bool IsLetter(char ch);
522 
528  static String ToLowerCase(const String &rValue);
529 
535  static String ToUpperCase(const String &rValue);
536  }; // class StringHelper
537 
541 
546  {
547  public:
552  const String& ToString() const;
553 
557  void Clear();
558 
559  public:
564 // StringBuilder& operator << (char value);
565 
571  StringBuilder& operator << (kt_int8u value);
572 
578  StringBuilder& operator << (kt_int16s value);
584  StringBuilder& operator << (kt_int16u value);
585 
591  StringBuilder& operator << (kt_int32s value);
597  StringBuilder& operator << (kt_int32u value);
598 
604  StringBuilder& operator << (kt_int64s value);
610  StringBuilder& operator << (kt_int64u value);
611 
612 #if defined(__APPLE__) && !defined(__LP64__)
613 
618  StringBuilder& operator << (kt_size_t value);
619 #endif
620 
626  StringBuilder& operator << (kt_float value);
632  StringBuilder& operator << (kt_double value);
633 
639  StringBuilder& operator << (const String& rValue);
640 
646  StringBuilder& operator << (const StringBuilder& rValue);
647 
654  friend KARTO_FORCEINLINE std::ostream& operator << (std::ostream& rStream, const StringBuilder& rStringBuilder)
655  {
656  rStream << rStringBuilder.ToString();
657  return rStream;
658  }
659 
660  private:
662  }; // class StringBuilder
663 
665 
666 }
667 
668 #endif // __OpenKarto_StringHelper_h__
static kt_bool FromString(const String &rStringValue, Size2< T > &rValue)
Definition: StringHelper.h:301
bool kt_bool
Definition: Types.h:145
void SetY(const T &y)
Definition: Geometry.h:699
void SetW(const T &w)
Definition: Geometry.h:1164
std::size_t kt_size_t
Definition: Types.h:138
static kt_bool FromString(const String &rStringValue, Vector2< T > &rValue)
Definition: StringHelper.h:334
int16_t kt_int16s
Definition: Types.h:96
void SetWidth(T width)
Definition: Geometry.h:89
kt_size_t FindFirstOf(const String &rValue) const
Definition: String.cpp:102
#define KARTO_EXPORT
Definition: Macros.h:78
void SetX(const T &x)
Definition: Geometry.h:360
String SubString(kt_size_t index) const
Definition: String.cpp:87
void SetZ(const T &z)
Definition: Geometry.h:1146
void SetY(const T &y)
Definition: Geometry.h:1128
float kt_float
Definition: Types.h:155
uint8_t kt_int8u
Definition: Types.h:91
#define KARTO_FORCEINLINE
Definition: Macros.h:56
uint32_t kt_int32u
Definition: Types.h:111
void SetX(const T &x)
Definition: Geometry.h:681
TFSIMD_FORCE_INLINE Vector3()
static kt_bool FromString(const String &rStringValue, Vector4< T > &rValue)
Definition: StringHelper.h:416
const String & ToString() const
int32_t kt_int32s
Definition: Types.h:106
static kt_bool FromString(const String &rStringValue, Vector3< T > &rValue)
Definition: Geometry.h:3252
void SetHeight(T height)
Definition: Geometry.h:107
double kt_double
Definition: Types.h:160
void SetX(const T &x)
Definition: Geometry.h:1110
signed long long kt_int64s
Definition: Types.h:127
uint16_t kt_int16u
Definition: Types.h:101
Definition: Any.cpp:20
unsigned long long kt_int64u
Definition: Types.h:132
void SetZ(const T &z)
Definition: Geometry.h:717
kt_size_t Size() const
Definition: String.cpp:77
void SetY(const T &y)
Definition: Geometry.h:378
static kt_bool FromString(const String &rStringValue, Vector3< T > &rValue)
Definition: StringHelper.h:367


nav2d_karto
Author(s): Sebastian Kasperski
autogenerated on Thu Jun 6 2019 19:20:25