liblcf
ReaderUtil Namespace Reference

Functions

std::string CodepageToEncoding (int codepage)
 
std::string DetectEncoding (std::istream &filestream)
 
std::string DetectEncoding (const std::string &data)
 
std::vector< std::string > DetectEncodings (std::istream &filestream)
 
std::vector< std::string > DetectEncodings (const std::string &data)
 
std::string GetEncoding (const std::string &ini_file)
 
std::string GetEncoding (std::istream &filestream)
 
std::string GetLocaleEncoding ()
 
std::string Recode (const std::string &str_to_encode, const std::string &source_encoding)
 
std::string Recode (const std::string &str_to_encode, const std::string &src_enc, const std::string &dst_enc)
 
std::string Normalize (const std::string &str)
 
template<typename T >
T * GetElement (std::vector< T > &vec, int one_based_index)
 
template<typename T >
const T * GetElement (const std::vector< T > &vec, int one_based_index)
 

Detailed Description

ReaderUtil namespace.

Function Documentation

◆ CodepageToEncoding()

std::string ReaderUtil::CodepageToEncoding ( int  codepage)

Returns the encoding name of a windows numeric codepage.

Parameters
codepagecodepage to lookup.
Returns
name used by the converter or empty string if not found.

Definition at line 50 of file reader_util.cpp.

Referenced by GetEncoding(), GetLocaleEncoding(), Encoder::Init(), and Recode().

+ Here is the caller graph for this function:

◆ DetectEncoding() [1/2]

std::string ReaderUtil::DetectEncoding ( const std::string &  data)

Detects the encoding based on text analysis.

Parameters
filestreamstream containing the database file
Returns
encoding or empty string if not detected.

Definition at line 90 of file reader_util.cpp.

References Data::data, and DetectEncodings().

+ Here is the call graph for this function:

◆ DetectEncoding() [2/2]

std::string ReaderUtil::DetectEncoding ( std::istream &  filestream)

Detects the encoding based on text analysis.

Parameters
filestreamstream containing the database file
Returns
encoding or empty string if not detected.

Definition at line 80 of file reader_util.cpp.

References DetectEncodings().

+ Here is the call graph for this function:

◆ DetectEncodings() [1/2]

std::vector< std::string > ReaderUtil::DetectEncodings ( const std::string &  data)

Detects the encoding based on text analysis and returns a vector with possible candidates, highest candidate being at the beginning.

Parameters
stringencoded data of a few hundred bytes
Returns
list of encodings or empty if not detected

Definition at line 158 of file reader_util.cpp.

References Data::data.

◆ DetectEncodings() [2/2]

std::vector< std::string > ReaderUtil::DetectEncodings ( std::istream &  filestream)

Detects the encoding based on text analysis and returns a vector with possible candidates, highest candidate being at the beginning.

Parameters
filestreamstream containing the database file
Returns
list of encodings or empty if not detected

Definition at line 100 of file reader_util.cpp.

References RPG::Terms::accessory, RPG::Terms::agility, RPG::System::airship_name, RPG::Terms::armor, RPG::Terms::attack, RPG::System::battletest_background, RPG::System::boat_name, RPG::Terms::defense, RPG::Terms::exit_game, RPG::Terms::exit_game_message, RPG::Terms::exp_short, RPG::Terms::file, RPG::System::frame_name, RPG::System::gameover_name, RPG::Terms::health_points, RPG::Terms::helmet, RPG::Terms::hp_short, RPG::Terms::level, LDB_Reader::Load(), RPG::Terms::load_game, RPG::Terms::load_game_message, RPG::Terms::lvl_short, RPG::Terms::menu_quit, RPG::Terms::menu_save, RPG::Terms::new_game, RPG::Terms::no, RPG::Terms::normal_status, RPG::Terms::order, RPG::Terms::row, RPG::Terms::save_game_message, RPG::Terms::shield, RPG::System::ship_name, RPG::Terms::sp_cost, RPG::Terms::sp_short, RPG::Terms::spirit, RPG::Terms::spirit_points, RPG::Terms::status, Data::system, RPG::System::system2_name, RPG::System::system_name, Data::terms, RPG::System::title_name, RPG::Terms::wait_off, RPG::Terms::wait_on, RPG::Terms::weapon, and RPG::Terms::yes.

Referenced by DetectEncoding().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetElement() [1/2]

template<typename T >
const T* ReaderUtil::GetElement ( const std::vector< T > &  vec,
int  one_based_index 
)

Helper function that returns an element from a vector using a 1-based index as usually used by LCF data structures.

Parameters
vecVector to return element from
one_based_indexindex to access vector at "index - 1"
Returns
element or nullptr when "index - 1" is out of bounds

Definition at line 153 of file reader_util.h.

◆ GetElement() [2/2]

template<typename T >
T* ReaderUtil::GetElement ( std::vector< T > &  vec,
int  one_based_index 
)

Helper function that returns an element from a vector using a 1-based index as usually used by LCF data structures.

Parameters
vecVector to return element from
one_based_indexindex to access vector at "index - 1"
Returns
element or nullptr when "index - 1" is out of bounds

Definition at line 131 of file reader_util.h.

◆ GetEncoding() [1/2]

std::string ReaderUtil::GetEncoding ( const std::string &  ini_file)

Returns the encoding set in the ini file.

Parameters
ini_fileThe ini file to parse.
Returns
encoding or empty string if not found.

Definition at line 207 of file reader_util.cpp.

References CodepageToEncoding(), INIReader::Get(), and INIReader::ParseError().

+ Here is the call graph for this function:

◆ GetEncoding() [2/2]

std::string ReaderUtil::GetEncoding ( std::istream &  filestream)

Returns the encoding set in the ini file.

Parameters
filestreamThe ini file to parse.
Returns
encoding or empty string if not found.

Definition at line 218 of file reader_util.cpp.

References CodepageToEncoding(), INIReader::Get(), and INIReader::ParseError().

+ Here is the call graph for this function:

◆ GetLocaleEncoding()

std::string ReaderUtil::GetLocaleEncoding ( )

Returns the system encoding based on current locale settings.

Returns
system encoding or western if no locale found.

Definition at line 229 of file reader_util.cpp.

References CodepageToEncoding().

+ Here is the call graph for this function:

◆ Normalize()

std::string ReaderUtil::Normalize ( const std::string &  str)

Converts a UTF-8 string to lowercase and then decomposes it.

Parameters
strthe string to normalize.
Returns
the normalized string.

Definition at line 376 of file reader_util.cpp.

◆ Recode() [1/2]

std::string ReaderUtil::Recode ( const std::string &  str_to_encode,
const std::string &  source_encoding 
)

Converts a string to unicode.

Parameters
str_to_encodestring to encode
source_encodingEncoding of str_to_encode
Returns
the recoded string.

Definition at line 286 of file reader_util.cpp.

◆ Recode() [2/2]

std::string ReaderUtil::Recode ( const std::string &  str_to_encode,
const std::string &  src_enc,
const std::string &  dst_enc 
)

Converts a string between encodings.

Parameters
str_to_encodethe string to convert.
src_encthe source encoding.
dst_encthe destination encoding.
Returns
the recoded string.

Definition at line 290 of file reader_util.cpp.

References CodepageToEncoding(), and makeScopeGuard().

+ Here is the call graph for this function: