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 icu::UnicodeString fo::recodeToUnicode(const std::string &input)
33 {
34  int len = input.length();
35  const unsigned char *in =
36  reinterpret_cast<const unsigned char*>(input.c_str());
37 
38  icu::UnicodeString out;
39  for (int i = 0; i < len;)
40  {
41  UChar32 uniChar;
42  int lastPos = i;
43  U8_NEXT(in, i, len, uniChar);
44  if (uniChar > 0)
45  {
46  out.append(uniChar);
47  }
48  else
49  {
50  i = lastPos;
51  U16_NEXT(in, i, len, uniChar);
52  if (U_IS_UNICODE_CHAR(uniChar) && uniChar > 0)
53  {
54  out.append(uniChar);
55  }
56  }
57  }
58  out.trim();
59  return out;
60 }
General utility functions for CPP.
unsigned long stringToUnsignedLong(const char *string)
Definition: libfossUtils.cc:20
icu::UnicodeString recodeToUnicode(const std::string &input)
Definition: libfossUtils.cc:32