FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
libfossUtils.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2015, Siemens AG
3 
4  This program is free software; you can redistribute it and/or
5  modify it under the terms of the GNU General Public License version 2
6  as published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  See the GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software Foundation,
15  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 */
17 #include <sstream>
18 
19 #include "libfossUtils.hpp"
20 
31 unsigned long fo::stringToUnsignedLong(const char* string)
32 {
33  unsigned long uLongVariable;
34  std::stringstream(string) >> uLongVariable;
35  return uLongVariable;
36 }
37 
43 icu::UnicodeString fo::recodeToUnicode(const std::string &input)
44 {
45  int len = input.length();
46  const unsigned char *in =
47  reinterpret_cast<const unsigned char*>(input.c_str());
48 
49  icu::UnicodeString out;
50  for (int i = 0; i < len;)
51  {
52  UChar32 uniChar;
53  int lastPos = i;
54  U8_NEXT(in, i, len, uniChar);
55  if (uniChar > 0)
56  {
57  out.append(uniChar);
58  }
59  else
60  {
61  i = lastPos;
62  U16_NEXT(in, i, len, uniChar);
63  if (U_IS_UNICODE_CHAR(uniChar) && uniChar > 0)
64  {
65  out.append(uniChar);
66  }
67  }
68  }
69  out.trim();
70  return out;
71 }
unsigned long stringToUnsignedLong(const char *string)
Definition: libfossUtils.cc:31
General utility functions for CPP.
icu::UnicodeString recodeToUnicode(const std::string &input)
Definition: libfossUtils.cc:43