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

Last change on this file since 1181 was 1179, checked in by Maciej Komosinski, 21 months ago

"eof" quoting and unquoting functions (used in client-server communication)

  • Property svn:eol-style set to native
File size: 2.6 KB
RevLine 
[286]1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
[1179]2// Copyright (C) 1999-2022  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]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);
[257]14bool loadSStringLine(VirtFILE* f, SString &s);
[109]15
16int quoteTilde(SString &target);
17int unquoteTilde(SString &target);
18
[257]19bool strContainsOneOf(const char* str, const char* chars);
[109]20bool sstringQuote(SString& target);
[786]21SString sstringDelimitAndShorten(const SString &in, int maxlen, bool show_length, const SString& before, const SString& after);
[109]22const char* skipQuoteString(const char* txt, const char* limit);
23int sstringUnquote(SString &target);
24
[1156]25bool sstringURLEncode(SString& target);
26bool sstringURLDecode(SString &target);
[1179]27bool sstringQuoteEOF(SString& target);
28bool sstringUnquoteEOF(SString& target);
[1156]29
[257]30int strFindField(const SString& txt, const SString& name, int &end);
31SString strGetField(const SString& txt, const SString& name);
32void strSetField(SString& txt, const SString& name, const SString& value);
[109]33
[512]34SString trim(const SString& s); ///< remove leading/trailing whitespace
[929]35SString concatPath(const SString& in1, const SString& in2); ///< concatenate path components inserting PATH_SEPARATOR_CHAR if not already present
[210]36bool removeCR(SString& s); ///< remove '\r' return true if changed
[257]37bool matchWildcard(const SString& word, const SString& pattern);///< '*' in pattern matches any substring
38bool matchWildcardList(const SString& word, const SString& patterns);///< patterns is a list of patterns (separated by ',')
[691]39SString getUIDString(uint64_t uid, char prefix);
40bool parseUIDString(const char* str, char prefix, uint64_t &uid, bool err);
[109]41
[929]42// SplitResult can be any class implementing push_back(const SString&), e.g. std::vector<SString>
43template <class SplitResult> void strSplit(const SString& text, const SString& separator, bool merge_separators, SplitResult& result)
44{
45        int i, next = 0;
46        bool first = true;
[973]47        if (!separator.length()) { result.push_back(text); return; }
[929]48        while (1)
49        {
50                i = text.indexOf(separator.c_str(), next);
51                if (i < 0)
52                {
[973]53                        if ((next <= text.length()) || first)
[929]54                                result.push_back(text.substr(next));
55                        return;
56                }
57                if ((!merge_separators) || (i > next) || (i == 0))
58                {
59                        result.push_back(text.substr(next, i - next));
60                        first = false;
61                }
[973]62                next = i + separator.length();
[929]63        }
64}
65
66
[109]67#endif
Note: See TracBrowser for help on using the repository browser.