CARLA
rpc/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
13 #include "UnrealString.h"
15 #endif // LIBCARLA_INCLUDED_FROM_UE4
16 
17 namespace carla {
18 namespace rpc {
19 
20 #ifdef LIBCARLA_INCLUDED_FROM_UE4
21 
22  // Fast conversion from fstring
23  static inline std::string FromFString(const FString &Str) {
24  return TCHAR_TO_UTF8(*Str);
25  }
26 
27  // Fast conversion to fstring
28  static inline FString ToFString(const std::string &str) {
29  return FString(str.size(), UTF8_TO_TCHAR(str.c_str()));
30  }
31 
32  constexpr size_t MaxStringLength = 5000000;
33 
34  // Slower conversion from fstring for long text
35  static inline std::string FromLongFString(const FString &Str) {
36  std::string result;
37  size_t i = 0;
38  while(i + MaxStringLength < Str.Len()) {
39  auto Substr = Str.Mid(i, MaxStringLength);
40  std::string temp_string = TCHAR_TO_UTF8(*Substr);
41  result += temp_string;
42  i += MaxStringLength;
43  }
44  auto Substr = Str.Mid(i, Str.Len() - i);
45  std::string temp_string = TCHAR_TO_UTF8(*Substr);
46  result += temp_string;
47  return result;
48  }
49 
50  // Slower conversion to fstring for long text
51  static inline FString ToLongFString(const std::string &str) {
52  FString result = "";
53  for (size_t i = 0; i < str.size(); i++)
54  {
55  result += str[i];
56  }
57  return result;
58  }
59 
60 #endif // LIBCARLA_INCLUDED_FROM_UE4
61 
62 } // namespace rpc
63 } // namespace carla
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133