• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #ifndef CORE_FXCRT_FX_STRING_H_
8 #define CORE_FXCRT_FX_STRING_H_
9 
10 #include <stdint.h>
11 
12 #include <vector>
13 
14 #include "core/fxcrt/bytestring.h"
15 #include "core/fxcrt/widestring.h"
16 
17 #define FXBSTR_ID(c1, c2, c3, c4)                                      \
18   (((uint32_t)c1 << 24) | ((uint32_t)c2 << 16) | ((uint32_t)c3 << 8) | \
19    ((uint32_t)c4))
20 
21 ByteString FX_UTF8Encode(WideStringView wsStr);
22 WideString FX_UTF8Decode(ByteStringView bsStr);
23 
24 float StringToFloat(ByteStringView str);
25 float StringToFloat(WideStringView wsStr);
26 size_t FloatToString(float f, char* buf);
27 
28 double StringToDouble(ByteStringView str);
29 double StringToDouble(WideStringView wsStr);
30 size_t DoubleToString(double d, char* buf);
31 
32 namespace fxcrt {
33 
34 template <typename StrType>
Split(const StrType & that,typename StrType::CharType ch)35 std::vector<StrType> Split(const StrType& that, typename StrType::CharType ch) {
36   std::vector<StrType> result;
37   StringViewTemplate<typename StrType::CharType> remaining(that.span());
38   while (1) {
39     Optional<size_t> index = remaining.Find(ch);
40     if (!index.has_value())
41       break;
42     result.emplace_back(remaining.First(index.value()));
43     remaining = remaining.Last(remaining.GetLength() - index.value() - 1);
44   }
45   result.emplace_back(remaining);
46   return result;
47 }
48 
49 }  // namespace fxcrt
50 
51 #endif  // CORE_FXCRT_FX_STRING_H_
52