StringUtil.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #ifndef STRINGUTIL_H_
  19. #define STRINGUTIL_H_
  20. #include <stdint.h>
  21. #include <vector>
  22. #include <string>
  23. namespace NativeTask {
  24. using std::vector;
  25. using std::string;
  26. class StringUtil {
  27. public:
  28. static string ToString(int32_t v);
  29. static string ToString(uint32_t v);
  30. static string ToString(int64_t v);
  31. static string ToString(int64_t v, char pad, int64_t len);
  32. static string ToString(uint64_t v);
  33. static string ToString(bool v);
  34. static string ToString(float v);
  35. static string ToString(double v);
  36. static string ToHexString(const void * v, uint32_t len);
  37. static int64_t toInt(const string & str);
  38. static bool toBool(const string & str);
  39. static float toFloat(const string & str);
  40. static string Format(const char * fmt, ...);
  41. static void Format(string & dest, const char * fmt, ...);
  42. static string ToLower(const string & name);
  43. static string Trim(const string & str);
  44. static void Split(const string & src, const string & sep, vector<string> & dest,
  45. bool clean = false);
  46. static string Join(const vector<string> & strs, const string & sep);
  47. static bool StartsWith(const string & str, const string & prefix);
  48. static bool EndsWith(const string & str, const string & suffix);
  49. };
  50. } // namespace NativeTask
  51. #endif /* STRINGUTIL_H_ */