source: cpp/frams/util/sstringutils.h @ 1156

Last change on this file since 1156 was 1156, checked in by Maciej Komosinski, 10 months ago

Added sstringURLEncode(SString& target) and sstringURLDecode(SString &target)

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