[286] | 1 | // This file is a part of Framsticks SDK. http://www.framsticks.com/ |
---|
[929] | 2 | // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. |
---|
[286] | 3 | // See LICENSE.txt for details. |
---|
[109] | 4 | |
---|
| 5 | #ifndef _SSTRINGUTILS_H_ |
---|
| 6 | #define _SSTRINGUTILS_H_ |
---|
| 7 | |
---|
| 8 | #include "sstring.h" |
---|
[382] | 9 | #include <common/virtfile/virtfile.h> |
---|
[109] | 10 | |
---|
| 11 | /// return: 1=ok 0=error |
---|
[691] | 12 | int loadSString(const char* filename, SString& s, const char* framsgmodule = 0, const char* error = 0, bool remove_cr = true); |
---|
| 13 | void loadSString(VirtFILE *f, SString& s, bool remove_cr = true); |
---|
[257] | 14 | bool loadSStringLine(VirtFILE* f, SString &s); |
---|
[109] | 15 | |
---|
| 16 | int quoteTilde(SString &target); |
---|
| 17 | int unquoteTilde(SString &target); |
---|
| 18 | |
---|
[257] | 19 | bool strContainsOneOf(const char* str, const char* chars); |
---|
[109] | 20 | bool sstringQuote(SString& target); |
---|
[786] | 21 | SString sstringDelimitAndShorten(const SString &in, int maxlen, bool show_length, const SString& before, const SString& after); |
---|
[109] | 22 | const char* skipQuoteString(const char* txt, const char* limit); |
---|
| 23 | int sstringUnquote(SString &target); |
---|
| 24 | |
---|
[257] | 25 | int strFindField(const SString& txt, const SString& name, int &end); |
---|
| 26 | SString strGetField(const SString& txt, const SString& name); |
---|
| 27 | void strSetField(SString& txt, const SString& name, const SString& value); |
---|
[109] | 28 | |
---|
[512] | 29 | SString trim(const SString& s); ///< remove leading/trailing whitespace |
---|
[929] | 30 | SString concatPath(const SString& in1, const SString& in2); ///< concatenate path components inserting PATH_SEPARATOR_CHAR if not already present |
---|
[210] | 31 | bool removeCR(SString& s); ///< remove '\r' return true if changed |
---|
[257] | 32 | bool matchWildcard(const SString& word, const SString& pattern);///< '*' in pattern matches any substring |
---|
| 33 | bool matchWildcardList(const SString& word, const SString& patterns);///< patterns is a list of patterns (separated by ',') |
---|
[691] | 34 | SString getUIDString(uint64_t uid, char prefix); |
---|
| 35 | bool parseUIDString(const char* str, char prefix, uint64_t &uid, bool err); |
---|
[109] | 36 | |
---|
[929] | 37 | // SplitResult can be any class implementing push_back(const SString&), e.g. std::vector<SString> |
---|
| 38 | template <class SplitResult> void strSplit(const SString& text, const SString& separator, bool merge_separators, SplitResult& result) |
---|
| 39 | { |
---|
| 40 | int i, next = 0; |
---|
| 41 | bool first = true; |
---|
[973] | 42 | if (!separator.length()) { result.push_back(text); return; } |
---|
[929] | 43 | while (1) |
---|
| 44 | { |
---|
| 45 | i = text.indexOf(separator.c_str(), next); |
---|
| 46 | if (i < 0) |
---|
| 47 | { |
---|
[973] | 48 | if ((next <= text.length()) || first) |
---|
[929] | 49 | result.push_back(text.substr(next)); |
---|
| 50 | return; |
---|
| 51 | } |
---|
| 52 | if ((!merge_separators) || (i > next) || (i == 0)) |
---|
| 53 | { |
---|
| 54 | result.push_back(text.substr(next, i - next)); |
---|
| 55 | first = false; |
---|
| 56 | } |
---|
[973] | 57 | next = i + separator.length(); |
---|
[929] | 58 | } |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | |
---|
[109] | 62 | #endif |
---|