47 行
1.4 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net>
  5. // © 2013—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com>
  6. //
  7. // Lol Engine is free software. It comes without any warranty, to
  8. // the extent permitted by applicable law. You can redistribute it
  9. // and/or modify it under the terms of the Do What the Fuck You Want
  10. // to Public License, Version 2, as published by the WTFPL Task Force.
  11. // See http://www.wtfpl.net/ for more details.
  12. //
  13. #pragma once
  14. //
  15. // The string tools
  16. // ----------------
  17. // Contains some utilities to work with std::string objects.
  18. //
  19. #include <string>
  20. namespace lol
  21. {
  22. /* Split a string along a single separator */
  23. array<std::string> split(std::string const &s, char sep = '\n');
  24. /* Split a string along multiple separators */
  25. array<std::string> split(std::string const &s, std::string const &seps);
  26. /* Check whether a string starts or ends with a given substring */
  27. bool starts_with(std::string const &s, std::string const &prefix);
  28. bool ends_with(std::string const &s, std::string const &suffix);
  29. /* Convert a string to lowercase or uppercase */
  30. std::string tolower(std::string const &s);
  31. std::string toupper(std::string const &s);
  32. /* Format a string, printf-style */
  33. std::string format(char const *format, ...) LOL_ATTR_FORMAT(1, 2);
  34. std::string vformat(char const *format, va_list ap);
  35. } /* namespace lol */