parse_helper.h 975 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // This file is part of Desktop App Toolkit,
  2. // a set of libraries for developing nice desktop applications.
  3. //
  4. // For license and copyright information please follow this link:
  5. // https://github.com/desktop-app/legal/blob/master/LEGAL
  6. //
  7. #pragma once
  8. namespace base {
  9. namespace parse {
  10. // Strip all C-style comments.
  11. QByteArray stripComments(const QByteArray &content);
  12. inline bool skipWhitespaces(const char *&from, const char *end) {
  13. Assert(from <= end);
  14. while (from != end && (
  15. (*from == ' ') ||
  16. (*from == '\n') ||
  17. (*from == '\t') ||
  18. (*from == '\r'))) {
  19. ++from;
  20. }
  21. return (from != end);
  22. }
  23. inline QLatin1String readName(const char *&from, const char *end) {
  24. Assert(from <= end);
  25. auto start = from;
  26. while (from != end && (
  27. (*from >= 'a' && *from <= 'z') ||
  28. (*from >= 'A' && *from <= 'Z') ||
  29. (*from >= '0' && *from <= '9') ||
  30. (*from == '_'))) {
  31. ++from;
  32. }
  33. return QLatin1String(start, from - start);
  34. }
  35. } // namespace parse
  36. } // namespace base