FOSSology  4.4.0
Open Source License Compliance by Open Source Software
libfossUtils.cc
Go to the documentation of this file.
1 /*
2  SPDX-FileCopyrightText: © 2014-2015 Siemens AG
3 
4  SPDX-License-Identifier: GPL-2.0-only
5 */
6 #include <sstream>
7 
8 #include "libfossUtils.hpp"
9 
20 unsigned long fo::stringToUnsignedLong(const char* string)
21 {
22  unsigned long uLongVariable;
23  std::stringstream(string) >> uLongVariable;
24  return uLongVariable;
25 }
26 
32 bool fo::stringToBool(const char* str)
33 {
34  std::string str2(str);
35  if(str2 == "true" || str2 == "t")
36  return true;
37  else
38  return false;
39 }
40 
46 icu::UnicodeString fo::recodeToUnicode(const std::string &input)
47 {
48  int len = input.length();
49  const unsigned char *in =
50  reinterpret_cast<const unsigned char*>(input.c_str());
51 
52  icu::UnicodeString out;
53  for (int i = 0; i < len;)
54  {
55  UChar32 uniChar;
56  int lastPos = i;
57  U8_NEXT(in, i, len, uniChar);
58  if (uniChar > 0)
59  {
60  out.append(uniChar);
61  }
62  else
63  {
64  i = lastPos;
65  U16_NEXT(in, i, len, uniChar);
66  if (U_IS_UNICODE_CHAR(uniChar) && uniChar > 0)
67  {
68  out.append(uniChar);
69  }
70  }
71  }
72  out.trim();
73  return out;
74 }
General utility functions for CPP.
bool stringToBool(const char *string)
Definition: libfossUtils.cc:32
unsigned long stringToUnsignedLong(const char *string)
Definition: libfossUtils.cc:20
icu::UnicodeString recodeToUnicode(const std::string &input)
Definition: libfossUtils.cc:46