CARLA
String.h
Go to the documentation of this file.
1 // Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
2 // de Barcelona (UAB).
3 //
4 // This work is licensed under the terms of the MIT license.
5 // For a copy, see <https://opensource.org/licenses/MIT>.
6 
7 #pragma once
8 
9 #include <string>
10 
11 #ifdef LIBCARLA_INCLUDED_FROM_UE4
12 # include "UnrealString.h"
13 #endif // LIBCARLA_INCLUDED_FROM_UE4
14 
15 namespace carla {
16 namespace rpc {
17 
18 #ifdef LIBCARLA_INCLUDED_FROM_UE4
19 
20  // Fast conversion from fstring
21  static inline std::string FromFString(const FString &Str) {
22  return TCHAR_TO_UTF8(*Str);
23  }
24 
25  // Fast conversion to fstring
26  static inline FString ToFString(const std::string &str) {
27  return FString(str.size(), UTF8_TO_TCHAR(str.c_str()));
28  }
29 
30  constexpr size_t MaxStringLength = 5000000;
31 
32  // Slower conversion from fstring for long text
33  static inline std::string FromLongFString(const FString &Str) {
34  std::string result;
35  size_t i = 0;
36  while(i + MaxStringLength < Str.Len()) {
37  auto Substr = Str.Mid(i, MaxStringLength);
38  std::string temp_string = TCHAR_TO_UTF8(*Substr);
39  result += temp_string;
40  i += MaxStringLength;
41  }
42  auto Substr = Str.Mid(i, Str.Len() - i);
43  std::string temp_string = TCHAR_TO_UTF8(*Substr);
44  result += temp_string;
45  return result;
46  }
47 
48  // Slower conversion to fstring for long text
49  static inline FString ToLongFString(const std::string &str) {
50  FString result = "";
51  for (size_t i = 0; i < str.size(); i++)
52  {
53  result += str[i];
54  }
55  return result;
56  }
57 
58 #endif // LIBCARLA_INCLUDED_FROM_UE4
59 
60 } // namespace rpc
61 } // namespace carla
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:99