forked from OpenXcom/OpenXcom
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnicode.h
More file actions
93 lines (86 loc) · 3.44 KB
/
Copy pathUnicode.h
File metadata and controls
93 lines (86 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#pragma once
/*
* Copyright 2010-2016 OpenXcom Developers.
*
* This file is part of OpenXcom.
*
* OpenXcom is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenXcom is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*e
* You should have received a copy of the GNU General Public License
* along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string>
#include <stdint.h>
#include <SDL.h>
namespace OpenXcom
{
/**
* Represents a 32-bit Unicode codepoint.
* Not technically a character, but close enough for our purposes.
*/
typedef Uint32 UCode;
/**
* Represents a string where each character
* is a Unicode codepoint. Used for rendering text.
*/
typedef std::basic_string<UCode> UString;
/**
* Functions for dealing with encoding, strings, text
* and all related operations.
*/
namespace Unicode
{
/* Special text tokens */
const char TOK_NL_SMALL = 2; /// line break and change to small font
const char TOK_COLOR_FLIP = 1; /// alternate between primary and secondary color
const unsigned char TOK_NBSP = 0xA0; /// non-breaking space
/// Checks if a character is a linebreak.
inline bool isLinebreak(UCode c) { return (c == '\n' || c == TOK_NL_SMALL); }
/// Checks if a character is a blank space (includes non-breaking spaces).
inline bool isSpace(UCode c) { return (c == ' ' || c == TOK_NBSP); }
/// Checks if a character is a word separator.
inline bool isSeparator(UCode c) { return (c == '-' || c == '/'); }
/// Checks if a character is visible to the user.
inline bool isPrintable(UCode c) { return (c > 32 && c != TOK_NBSP); }
/// Find a UTF-8 locale.
void getUtf8Locale();
/// Converts a UTF-8 string to UTF-32.
UString convUtf8ToUtf32(const std::string &src);
/// Converts a UTF-32 string to UTF-8.
std::string convUtf32ToUtf8(const UString &src);
/// Converts a wide-char string to multi-byte.
std::string convWcToMb(const std::wstring &src, unsigned int cp = 0);
/// Converts a multi-byte string to wide-char.
std::wstring convMbToWc(const std::string &src, unsigned int cp = 0);
/// Converts a path to a UTF-8 string.
std::string convPathToUtf8(const std::string &src);
/// Converts a UTF-8 string to a path.
std::string convUtf8ToPath(const std::string &src);
/// Compares two strings by natural order.
bool naturalCompare(const std::string &a, const std::string &b);
/// Compares two strings case-insensitive.
bool caseCompare(const std::string &a, const std::string &b);
/// Find a string in another case-insensitive.
bool caseFind(const std::string &haystack, const std::string &needle);
/// Uppercases a string in place.
void upperCase(std::string &s);
/// Lowercases a string in place.
void lowerCase(std::string &s);
/// Replaces a substring.
void replace(std::string &str, const std::string &find, const std::string &replace);
/// Formats an integer value as number with separators.
std::string formatNumber(int64_t value, const std::string ¤cy = "");
/// Formats an integer value as currency.
std::string formatFunding(int64_t funds);
/// Formats an integer value as percentage.
std::string formatPercentage(int value);
}
}