Kodi Documentation 22.0
Kodi is an open source media player and entertainment hub.
Loading...
Searching...
No Matches
CPODocument Class Reference

#include <POUtils.h>

Public Member Functions

 CPODocument ()
 
 ~CPODocument ()
 
bool LoadFile (const std::string &pofilename)
 Tries to load a PO file into a temporary memory buffer. It also tries to parse the header of the PO file.
 
bool GetNextEntry ()
 Fast jumps to the next entry in PO buffer. Finds next entry started with "#: id:" or msgctx or msgid. to be as fast as possible this does not even get the id number just the type of the entry found. GetEntryID() has to be called for getting the id. After that ParseEntry() needs a call for actually getting the msg strings. The reason for this is to have calls and checks as fast as possible generally and specially for parsing weather tokens and to parse only the needed strings from the fallback language (missing from the gui language translation)
 
int GetEntryType () const
 Gets the type of entry found with GetNextEntry.
 
uint32_t GetEntryID () const
 Parses the numeric ID from current entry. This function can only be called right after GetNextEntry() to make sure that we have a valid entry detected.
 
void ParseEntry (bool bisSourceLang)
 Parses current entry. Reads msgid, msgstr, msgstr[x], msgctxt strings. Note that this function also back-converts the c++ style escape sequences. The function only parses the needed strings, considering if it is a source language file.
 
const std::string & GetMsgctxt () const
 Gets the msgctxt string previously parsed by ParseEntry().
 
const std::string & GetMsgid () const
 Gets the msgid string previously parsed by ParseEntry().
 
const std::string & GetMsgstr () const
 Gets the msgstr string previously parsed by ParseEntry().
 
const std::string & GetPlurMsgstr (size_t plural) const
 Gets the msgstr[x] string previously parsed by ParseEntry().
 

Protected Member Functions

std::string UnescapeString (const std::string &strInput)
 Converts c++ style char escape sequences back to char. Supports: \v
\t \r " \0 \f \? \' \.
 
bool FindLineStart (const std::string &strToFind, size_t &FoundPos)
 Finds the position of line, starting with a given string in current entry. This function can only be called after GetNextEntry()
 
void GetString (CStrEntry &strEntry)
 Reads, and links together the quoted strings found with ParseEntry(). This function can only be called after GetNextEntry() called.
 
bool ParseNumID ()
 Parses the numeric id and checks if it is valid. This function can only be called after GetNextEntry() It checks m_Entry.Content at position m_Entry.xIDPos for the numeric id. The converted ID number goes into m_Entry.xID for public read out.
 
void ConvertLineEnds (const std::string &filename)
 If we have Windows or Mac line-end chars in PO file, convert them to Unix LFs.
 

Protected Attributes

std::string m_strBuffer
 
size_t m_POfilelength
 
size_t m_CursorPos
 
size_t m_nextEntryPos
 
CPOEntry m_Entry
 

Constructor & Destructor Documentation

◆ CPODocument()

CPODocument::CPODocument ( )

◆ ~CPODocument()

CPODocument::~CPODocument ( )
default

Member Function Documentation

◆ ConvertLineEnds()

void CPODocument::ConvertLineEnds ( const std::string & filename)
protected

If we have Windows or Mac line-end chars in PO file, convert them to Unix LFs.

◆ FindLineStart()

bool CPODocument::FindLineStart ( const std::string & strToFind,
size_t & FoundPos )
protected

Finds the position of line, starting with a given string in current entry. This function can only be called after GetNextEntry()

Parameters
strToFinda string what we look for, at beginning of the lines.
FoundPoswill get the position where we found the line starting with the string.
Returns
false if no line like that can be found in the entry (m_Entry)

◆ GetEntryID()

uint32_t CPODocument::GetEntryID ( ) const
inline

Parses the numeric ID from current entry. This function can only be called right after GetNextEntry() to make sure that we have a valid entry detected.

Returns
parsed ID number

◆ GetEntryType()

int CPODocument::GetEntryType ( ) const
inline

Gets the type of entry found with GetNextEntry.

Returns
the type of entry: ID_FOUND || MSGID_FOUND || MSGID_PLURAL_FOUND

◆ GetMsgctxt()

const std::string & CPODocument::GetMsgctxt ( ) const
inline

Gets the msgctxt string previously parsed by ParseEntry().

Returns
string* containing the msgctxt string, unescaped and linked together.

◆ GetMsgid()

const std::string & CPODocument::GetMsgid ( ) const
inline

Gets the msgid string previously parsed by ParseEntry().

Returns
string* containing the msgid string, unescaped and linked together.

◆ GetMsgstr()

const std::string & CPODocument::GetMsgstr ( ) const
inline

Gets the msgstr string previously parsed by ParseEntry().

Returns
string* containing the msgstr string, unescaped and linked together.

◆ GetNextEntry()

bool CPODocument::GetNextEntry ( )

Fast jumps to the next entry in PO buffer. Finds next entry started with "#: id:" or msgctx or msgid. to be as fast as possible this does not even get the id number just the type of the entry found. GetEntryID() has to be called for getting the id. After that ParseEntry() needs a call for actually getting the msg strings. The reason for this is to have calls and checks as fast as possible generally and specially for parsing weather tokens and to parse only the needed strings from the fallback language (missing from the gui language translation)

Returns
true if there was an entry found, false if reached the end of buffer

◆ GetPlurMsgstr()

const std::string & CPODocument::GetPlurMsgstr ( size_t plural) const

Gets the msgstr[x] string previously parsed by ParseEntry().

Parameters
pluralthe number of plural-form expected to get (0-6).
Returns
string* containing the msgstr string, unescaped and linked together.

◆ GetString()

void CPODocument::GetString ( CStrEntry & strEntry)
protected

Reads, and links together the quoted strings found with ParseEntry(). This function can only be called after GetNextEntry() called.

Parameters
strEntry.Stra string where we get the appended string lines.
strEntry.Posthe position in m_Entry.Content to start reading the string.

◆ LoadFile()

bool CPODocument::LoadFile ( const std::string & pofilename)

Tries to load a PO file into a temporary memory buffer. It also tries to parse the header of the PO file.

Parameters
pofilenamefilename of the PO file to load.
Returns
true if the load was successful, unless return false

◆ ParseEntry()

void CPODocument::ParseEntry ( bool bisSourceLang)

Parses current entry. Reads msgid, msgstr, msgstr[x], msgctxt strings. Note that this function also back-converts the c++ style escape sequences. The function only parses the needed strings, considering if it is a source language file.

Parameters
bisSourceLangif we parse a source English file.

◆ ParseNumID()

bool CPODocument::ParseNumID ( )
protected

Parses the numeric id and checks if it is valid. This function can only be called after GetNextEntry() It checks m_Entry.Content at position m_Entry.xIDPos for the numeric id. The converted ID number goes into m_Entry.xID for public read out.

Returns
false, if parse and convert of the id number was unsuccessful.

◆ UnescapeString()

std::string CPODocument::UnescapeString ( const std::string & strInput)
protected

Converts c++ style char escape sequences back to char. Supports: \v
\t \r " \0 \f \? \' \.

Parameters
strInputstring contains the string to be unescaped.
Returns
unescaped string.

Member Data Documentation

◆ m_CursorPos

size_t CPODocument::m_CursorPos
protected

◆ m_Entry

CPOEntry CPODocument::m_Entry
protected

◆ m_nextEntryPos

size_t CPODocument::m_nextEntryPos
protected

◆ m_POfilelength

size_t CPODocument::m_POfilelength
protected

◆ m_strBuffer

std::string CPODocument::m_strBuffer
protected

The documentation for this class was generated from the following files: