当前位置:   article > 正文

Chromium Base库中常用的功能

chromium base

按模块划分

String

base/strings/string_util.h

  1. // Removes characters in |trim_chars| from the beginning and end of |input|.
  2. // The 8-bit version only works on 8-bit characters, not UTF-8. Returns true if
  3. // any characters were removed.
  4. //
  5. // It is safe to use the same variable for both |input| and |output| (this is
  6. // the normal usage to trim in-place).
  7. BASE_EXPORT bool TrimString(StringPiece16 input,
  8. StringPiece16 trim_chars,
  9. std::u16string* output);

去除首尾或首或尾指定子串。

相比folly::trim 易用性更好。

  1. // Replaces characters in |replace_chars| from anywhere in |input| with
  2. // |replace_with|. Each character in |replace_chars| will be replaced with
  3. // the |replace_with| string. Returns true if any characters were replaced.
  4. // |replace_chars| must be null-terminated.
  5. // NOTE: Safe to use the same variable for both |input| and |output|.
  6. BASE_EXPORT bool ReplaceChars(StringPiece16 input,
  7. StringPiece16 replace_chars,
  8. StringPiece16 replace_with,
  9. std::u16string* output);

替换字符串中的指定子串。

  1. // Converts the given string to it's ASCII-lowercase equivalent.
  2. BASE_EXPORT std::string ToLowerASCII(StringPiece str);
  3. BASE_EXPORT std::u16string ToLowerASCII(StringPiece16 str);
  4. // Converts the given string to it's ASCII-uppercase equivalent.
  5. BASE_EXPORT std::string ToUpperASCII(StringPiece str);
  6. BASE_EXPORT std::u16string ToUpperASCII(StringPiece16 str);

大小写转换

  1. // Indicates case sensitivity of comparisons. Only ASCII case insensitivity
  2. // is supported. Full Unicode case-insensitive conversions would need to go in
  3. // base/i18n so it can use ICU.
  4. //
  5. // If you need to do Unicode-aware case-insensitive StartsWith/EndsWith, it's
  6. // best to call base::i18n::ToLower() or base::i18n::FoldCase() (see
  7. // base/i18n/case_conversion.h for usage advice) on the arguments, and then use
  8. // the results to a case-sensitive comparison.
  9. enum class CompareCase {
  10. SENSITIVE,
  11. INSENSITIVE_ASCII,
  12. };
  13. BASE_EXPORT bool StartsWith(
  14. StringPiece str,
  15. StringPiece search_for,
  16. CompareCase case_sensitivity = CompareCase::SENSITIVE);
  17. BASE_EXPORT bool EndsWith(
  18. StringPiece str,
  19. StringPiece search_for,
  20. CompareCase case_sensitivity = CompareCase::SENSITIVE);

判断字符串是否以某子串起始或结束。

base/strings/string_split.h

  1. // Split the given string on ANY of the given separators, returning copies of
  2. // the result.
  3. //
  4. // Note this is inverse of JoinString() defined in string_util.h.
  5. //
  6. // To split on either commas or semicolons, keeping all whitespace:
  7. //
  8. // std::vector<std::string> tokens = base::SplitString(
  9. // input, ",;", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
  10. [[nodiscard]] BASE_EXPORT std::vector<std::string> SplitString(
  11. StringPiece input,
  12. StringPiece separators,
  13. WhitespaceHandling whitespace,
  14. SplitResult result_type);

分割字符串进vector。

CommandLine

base/command_line.h

  1. // This class works with command lines: building and parsing.
  2. // Arguments with prefixes ('--', '-', and on Windows, '/') are switches.
  3. // Switches will precede all other arguments without switch prefixes.
  4. // Switches can optionally have values, delimited by '=', e.g., "-switch=value".
  5. // If a switch is specified multiple times, only the last value is used.
  6. // An argument of "--" will terminate switch parsing during initialization,
  7. // interpreting subsequent tokens as non-switch arguments, regardless of prefix.
  8. class CommandLine
  9. // Returns true if this command line contains the given switch.
  10. // Switch names must be lowercase.
  11. // The second override provides an optimized version to avoid inlining codegen
  12. // at every callsite to find the length of the constant and construct a
  13. // StringPiece.
  14. bool HasSwitch(StringPiece switch_string) const;
  15. bool HasSwitch(const char switch_constant[]) const;
  16. // Returns the value associated with the given switch. If the switch has no
  17. // value or isn't present, this method returns the empty string.
  18. // Switch names must be lowercase.
  19. std::string GetSwitchValueASCII(StringPiece switch_string) const;
  20. FilePath GetSwitchValuePath(StringPiece switch_string) const;
  21. StringType GetSwitchValueNative(StringPiece switch_string) const;

解析命令行。

Process

base/process/launch.h

  1. // Launch a process via the command line |cmdline|.
  2. // See the documentation of LaunchOptions for details on |options|.
  3. //
  4. // Returns a valid Process upon success.
  5. BASE_EXPORT Process LaunchProcess(const CommandLine& cmdline,
  6. const LaunchOptions& options);

运行进程。

base/process/process.h

  1. // Provides a move-only encapsulation of a process.
  2. //
  3. // This object is not tied to the lifetime of the underlying process: the
  4. // process may be killed and this object may still around, and it will still
  5. // claim to be valid. The actual behavior in that case is OS dependent like so:
  6. //
  7. // Windows: The underlying ProcessHandle will be valid after the process dies
  8. // and can be used to gather some information about that process, but most
  9. // methods will obviously fail.
  10. class Process

获取进程信息。

base/hash/md5.h

  1. // Returns the MD5 (in hexadecimal) of a string.
  2. BASE_EXPORT std::string MD5String(const StringPiece& str);

生成MD5字符串。

base/files

文件相关系列操作。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/211452
推荐阅读
相关标签
  

闽ICP备14008679号