WPILibC++  unspecified
c_util.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #ifndef CSCORE_C_UTIL_H_
9 #define CSCORE_C_UTIL_H_
10 
11 #include <cstdlib>
12 #include <cstring>
13 
14 #include <llvm/StringRef.h>
15 
16 namespace cs {
17 
18 inline char* ConvertToC(llvm::StringRef in) {
19  char* out = static_cast<char*>(std::malloc(in.size() + 1));
20  std::memmove(out, in.data(), in.size());
21  out[in.size()] = '\0';
22  return out;
23 }
24 
25 } // namespace cs
26 
27 #endif // CSCORE_C_UTIL_H_
size_t size() const
size - Get the string size.
Definition: StringRef.h:149
Definition: SinkImpl.h:19
const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:139
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:42