liblcf
Loading...
Searching...
No Matches
reader_util.h
Go to the documentation of this file.
1/*
2 * This file is part of liblcf. Copyright (c) 2020 liblcf authors.
3 * https://github.com/EasyRPG/liblcf - https://easyrpg.org
4 *
5 * liblcf is Free/Libre Open Source Software, released under the MIT License.
6 * For the full copyright and license information, please view the COPYING
7 * file that was distributed with this source code.
8 */
9
10#ifndef LCF_READER_UTIL_H
11#define LCF_READER_UTIL_H
12
13#include <string>
14#include <vector>
15
19namespace ReaderUtil {
26 std::string CodepageToEncoding(int codepage);
27
35 std::string DetectEncoding(std::istream& filestream);
36
44 std::string DetectEncoding(const std::string& data);
45
54 std::vector<std::string> DetectEncodings(std::istream& filestream);
55
64 std::vector<std::string> DetectEncodings(const std::string& data);
65
73 std::string GetEncoding(const std::string& ini_file);
74
82 std::string GetEncoding(std::istream& filestream);
83
89 std::string GetLocaleEncoding();
90
99 std::string Recode(const std::string& str_to_encode, const std::string& source_encoding);
100
109 std::string Recode(const std::string& str_to_encode,
110 const std::string& src_enc,
111 const std::string& dst_enc);
112
119 std::string Normalize(const std::string &str);
120
121
130 template<typename T>
131 T* GetElement(std::vector<T>& vec, int one_based_index) {
132 if (one_based_index < 1) {
133 return nullptr;
134 }
135
136 // index is nonnegative, safe to cast
137 if (static_cast<typename std::vector<T>::size_type>(one_based_index) > vec.size()) {
138 return nullptr;
139 }
140
141 return &vec[one_based_index - 1];
142 }
143
152 template<typename T>
153 const T* GetElement(const std::vector<T>& vec, int one_based_index) {
154 if (one_based_index < 1) {
155 return nullptr;
156 }
157
158 // index is nonnegative, safe to cast
159 if (static_cast<typename std::vector<T>::size_type>(one_based_index) > vec.size()) {
160 return nullptr;
161 }
162
163 return &vec[one_based_index - 1];
164 }
165}
166
167#endif
std::string DetectEncoding(std::istream &filestream)
Definition: reader_util.cpp:80
std::string CodepageToEncoding(int codepage)
Definition: reader_util.cpp:50
std::vector< std::string > DetectEncodings(std::istream &filestream)
std::string GetLocaleEncoding()
std::string Normalize(const std::string &str)
std::string GetEncoding(const std::string &ini_file)
T * GetElement(std::vector< T > &vec, int one_based_index)
Definition: reader_util.h:131
std::string Recode(const std::string &str_to_encode, const std::string &source_encoding)