strutils.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #pragma once
  2. #include <string>
  3. #include <vector>
  4. #include "base/define.h"
  5. namespace ylib
  6. {
  7. namespace strutils{
  8. /**
  9. * @brief 删除子字符串
  10. * @param str
  11. * @param sub
  12. * @return
  13. */
  14. std::string remove(std::string str, const std::string& sub);
  15. /**
  16. * @brief 大小写转换
  17. * @param input
  18. * @param toUpperCase
  19. * @return
  20. */
  21. std::string change_case(const std::string& input, bool toUpperCase/*true=大写,false=小写*/);
  22. /**
  23. * @brief 分割字符串
  24. * @param str
  25. * @param delim
  26. * @return
  27. */
  28. std::vector<std::string> split(const std::string& str, const std::string& delim);
  29. std::vector<std::string> split(const std::string& str,char delim);
  30. /**
  31. * @brief 去首尾字符
  32. * @param str
  33. * @param chars
  34. * @return
  35. */
  36. std::string trim(std::string s,const std::vector<char>& trim_chars);
  37. /**
  38. * @brief 去首字符
  39. * @param str
  40. * @param chars
  41. * @return
  42. */
  43. std::string trim_begin(std::string s,const std::vector<char>& trim_chars);
  44. /**
  45. * @brief 去尾字符
  46. * @param str
  47. * @param chars
  48. * @param loop = 循环匹配
  49. * @return
  50. */
  51. std::string trim_end(std::string s,const std::vector<char>& trim_chars,bool loop = false);
  52. /**
  53. * @brief 左边
  54. * @param str
  55. * @param len
  56. * @return
  57. */
  58. std::string left(const std::string& str,size_t len);
  59. /**
  60. * @brief 右边
  61. * @param str
  62. * @param len
  63. * @return
  64. */
  65. std::string right(const std::string& str,size_t len);
  66. /**
  67. * @brief 是否为数字
  68. * @return
  69. */
  70. bool is_num(const std::string& str);
  71. bool is_num_code(char value);
  72. /**
  73. * @brief 是否为英文
  74. * @return
  75. */
  76. bool is_en_code(char value);
  77. /**
  78. * @brief 取中间
  79. * @param str
  80. * @param begin
  81. * @param end
  82. * @return
  83. */
  84. std::string between(const std::string& str,const std::string& begin,const std::string& end);
  85. /**
  86. * @brief 替换
  87. * @param str
  88. * @param search
  89. * @param value
  90. * @return
  91. */
  92. std::string replace(const std::string& str, const std::string& search, const std::string& value);
  93. std::string replace(const std::string& str, uchar search,uchar value);
  94. /**
  95. * @brief 空值
  96. */
  97. std::string F(const char* value);
  98. #ifdef _WIN32
  99. std::wstring to_wstring(const std::string& value);
  100. std::string wto_string(const std::wstring& value);
  101. #endif
  102. /// <summary>
  103. /// 填补
  104. /// </summary>
  105. /// <param name="value">输入</param>
  106. /// <param name="fixed_length">固定长度</param>
  107. /// <param name="pad">填补字符</param>
  108. /// <returns></returns>
  109. std::string pad_with_begin(const std::string& value,size_t fixed_length,char pad);
  110. std::string pad_with_end(const std::string& value, size_t fixed_length, char pad);
  111. }
  112. }