Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 andreas 1
/*
21 andreas 2
 * Copyright (C) 2020, 2021 by Andreas Theofilu <andreas@theosys.at>
4 andreas 3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software Foundation,
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
17
 */
18
 
19
#ifndef __TRESOURCES_H__
20
#define __TRESOURCES_H__
21
 
66 andreas 22
#include <deque>
87 andreas 23
#include <vector>
66 andreas 24
 
4 andreas 25
#include <include/core/SkImage.h>
26
#include <include/core/SkString.h>
27
#include <include/core/SkData.h>
28
 
29
class SkBitmap;
30
class SkData;
31
class SkStreamAsset;
57 andreas 32
class SkFont;
4 andreas 33
class SkTypeface;
34
 
35
extern sk_sp<SkData> (*gResourceFactory)(const char*);
36
 
37
SkString GetResourcePath(const char* resource = "");
38
 
39
bool DecodeDataToBitmap(sk_sp<SkData> data, SkBitmap* dst);
40
 
41
sk_sp<SkData> GetResourceAsData(const char* resource);
42
 
43
inline bool GetResourceAsBitmap(const char* resource, SkBitmap* dst)
44
{
45
    return DecodeDataToBitmap(GetResourceAsData(resource), dst);
46
}
47
 
48
inline sk_sp<SkImage> GetResourceAsImage(const char* resource)
49
{
50
    return SkImage::MakeFromEncoded(GetResourceAsData(resource));
51
}
52
 
53
std::unique_ptr<SkStreamAsset> GetResourceAsStream(const char* resource);
54
 
55
sk_sp<SkTypeface> MakeResourceAsTypeface(const char* resource, int ttcIndex = 0);
56
 
6 andreas 57
sk_sp<SkData> readImage(const std::string& fname);
58
 
21 andreas 59
std::string toLower(std::string& str);
60
std::string toUpper(std::string& str);
11 andreas 61
std::vector<std::string> StrSplit(const std::string& str, const std::string& seps, const bool trimEmpty=false);
62
std::string UTF8ToCp1250(const std::string& str);
63
std::string cp1250ToUTF8(const std::string& str);
64
std::string latin1ToUTF8(const std::string& str);
65
 
93 andreas 66
void *renew(char **mem, size_t old_size, size_t new_size);
54 andreas 67
std::vector<std::string> splitLine(const std::string& str);
57 andreas 68
std::vector<std::string> splitLine(const std::string& str, int width, int height, SkFont& font, SkPaint& paint);
60 andreas 69
bool isHex(int c);
70
int strCaseCompare(const std::string& str1, const std::string& str2);
63 andreas 71
std::string fillString(int c, int len);
67 andreas 72
bool isUTF8(const std::string& str);
73
size_t utf8Strlen(const std::string& str);
74
uint16_t getUint16(const unsigned char *p, bool big_endian=false);
75
uint32_t getUint32(const unsigned char *p, bool big_endian=false);
71 andreas 76
bool endsWith (const std::string &src, const std::string &end);
77
bool startsWith (const std::string &src, const std::string &start);
78
std::string dirName (const std::string &path);
79
std::string baseName (const std::string &path);
97 andreas 80
char *strnstr(const char *haystack, const char *needle, size_t len);
104 andreas 81
std::string getCommand(const std::string& fullCmd);
21 andreas 82
 
73 andreas 83
static inline std::string &ltrim(std::string &s)
84
{
85
    s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int c) {return !std::isspace(c);}));
86
    return s;
87
}
88
 
89
static inline std::string &rtrim(std::string &str)
90
{
91
    str.erase(str.find_last_not_of(" \n\r\t")+1);
92
    return str;
93
}
94
 
95
static inline std::string& trim(std::string& str) { return ltrim(rtrim(str)); }
96
 
4 andreas 97
#endif  // __TRESOURCES_H__