JX Application Framework
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | List of all members
JStringManager Class Reference

#include <JStringManager.h>

Inheritance diagram for JStringManager:
[legend]

Public Types

enum  {
  kASCIIFormat = 0 ,
  kUTF8Format = 1
}
 

Public Member Functions

 JStringManager ()
 
 ~JStringManager () override
 
void Register (const JUtf8Byte *signature, const JUtf8Byte **defaultData)
 
bool MergeFile (const JString &fileName, const bool debug=false)
 
bool MergeFile (std::istream &input, const bool debug=false)
 
void WriteFile (std::ostream &output) const
 
const JStringGetBCP47Locale () const
 
const JStringGet (const JUtf8Byte *id) const
 
JString Get (const JUtf8Byte *id, const JUtf8Byte *map[], const JSize size) const
 
JSubstituteGetReplaceEngine () const
 
void Replace (JString *str, const JUtf8Byte *map[], const JSize size) const
 
void ReportError (const JUtf8Byte *id, const JError &err) const
 
void ReportError (const JUtf8Byte *id, const JString &message) const
 
- Public Member Functions inherited from JStringPtrMap< JString >
 JStringPtrMap (const JPtrArrayT::CleanUpAction action, const JSize lgSize=kJDefaultLgMinTableSize)
 
 ~JStringPtrMap () override
 
bool GetItem (const JString &key, JString **ptr)
 
bool GetItem (const JString &key, const JString **ptr) const
 
bool GetItem (const JUtf8Byte *key, JString **ptr)
 
bool GetItem (const JUtf8Byte *key, const JString **ptr) const
 
bool SetItem (const JString &key, JString *ptr, const JPtrArrayT::SetAction action, const JStringMapT::SetType type=JStringMapT::kAlways)
 
bool SetItem (const JUtf8Byte *key, JString *ptr, const JPtrArrayT::SetAction action, const JStringMapT::SetType type=JStringMapT::kAlways)
 
bool SetItem (const JString &key, const JString &data, const JPtrArrayT::SetAction action, const JStringMapT::SetType type=JStringMapT::kAlways)
 
bool SetItem (const JUtf8Byte *key, const JString &data, const JPtrArrayT::SetAction action, const JStringMapT::SetType type=JStringMapT::kAlways)
 
bool SetOldItem (const JString &key, JString *ptr, const JPtrArrayT::SetAction action)
 
bool SetOldItem (const JUtf8Byte *key, JString *ptr, const JPtrArrayT::SetAction action)
 
bool SetOldItem (const JString &key, const JString &data, const JPtrArrayT::SetAction action)
 
bool SetOldItem (const JUtf8Byte *key, const JString &data, const JPtrArrayT::SetAction action)
 
bool SetContains (const JString &key, JString *ptr, const JPtrArrayT::SetAction action)
 
bool SetContains (const JUtf8Byte *key, JString *ptr, const JPtrArrayT::SetAction action)
 
bool SetContains (const JString &key, const JString &data, const JPtrArrayT::SetAction action)
 
bool SetContains (const JUtf8Byte *key, const JString &data, const JPtrArrayT::SetAction action)
 
bool SetNewItem (const JString &key, const JString &data)
 
bool SetNewItem (const JUtf8Byte *key, const JString &data)
 
bool DeleteItem (const JString &key)
 
bool DeleteItem (const JUtf8Byte *key)
 
bool DeleteItemAsArray (const JString &key)
 
bool DeleteItemAsArray (const JUtf8Byte *key)
 
void CleanOut ()
 
void DeleteAll ()
 
void DeleteAllAsArrays ()
 
JPtrArrayT::CleanUpAction GetCleanUpAction () const
 
void SetCleanUpAction (const JPtrArrayT::CleanUpAction action)
 
- Public Member Functions inherited from JStringMap< V >
 JStringMap (const JSize lgSize=kJDefaultLgMinTableSize)
 
 ~JStringMap () override
 
bool Contains (const JString &key) const
 
bool GetItem (const JString &key, V *value) const
 
bool SetItem (const JString &key, const V &value, const JStringMapT::SetType type=JStringMapT::kAlways)
 
bool SetNewItem (const JString &key, const V &value)
 
bool SetOldItem (const JString &key, const V &value)
 
bool SetContains (const JString &key, const V &value)
 
bool RemoveItem (const JString &key)
 
void RemoveAll ()
 
bool Contains (const JUtf8Byte *key) const
 
bool GetItem (const JUtf8Byte *key, V *value) const
 
bool SetItem (const JUtf8Byte *key, const V &value, const JStringMapT::SetType type=JStringMapT::kAlways)
 
bool SetNewItem (const JUtf8Byte *key, const V &value)
 
bool SetOldItem (const JUtf8Byte *key, const V &value)
 
bool SetContains (const JUtf8Byte *key, const V &value)
 
bool RemoveItem (const JUtf8Byte *key)
 
- Public Member Functions inherited from JHashTable< JStrValue< V > >
 JHashTable (const JSize lgSize=kJDefaultLgMinTableSize)
 
virtual ~JHashTable ()
 
bool IsEmpty () const
 
JSize GetItemCount () const
 
JSize GetLgSize () const
 
JSize GetLoadCount () const
 
JSize GetTableSize () const
 
JFloat GetFillFactor () const
 
JFloat GetLoadFactor () const
 
bool GetResizeEnabled () const
 
void SetResizeEnabled (const bool enabled)
 
JFloat GetMaxLoadFactor () const
 
void SetMaxLoadFactor (const JFloat newMax)
 
JFloat GetMinFillFactor () const
 
void SetMinFillFactor (const JFloat newMin)
 
JSize GetMinTableSize () const
 
void SetMinTableSize (const JSize newMin)
 
bool IsOK () const
 

Static Public Member Functions

static bool CanOverride (const JString &id)
 
static void EnablePseudotranslation ()
 

Additional Inherited Members

- Protected Member Functions inherited from JStringPtrMap< JString >
void PrepareForSet (const JPtrArrayT::SetAction action) override
 
- Protected Member Functions inherited from JStringMap< V >
bool SetItem (const JString &key, const V &value, const JPtrArrayT::SetAction action, const JStringMapT::SetType type, bool *existed)
 
bool RemoveItem (const JString &key, const JPtrArrayT::SetAction action)
 
void RemoveAll (const JPtrArrayT::SetAction action)
 
- Protected Member Functions inherited from JHashTable< JStrValue< V > >
bool IsEmpty (const JSize index) const
 
void AllowCursors ()
 
void DisallowCursors ()
 
JHashCursor< JStrValue< V > > * GetCursor ()
 
JConstHashCursor< JStrValue< V > > * GetCursor () const
 
const JHashRecord< JStrValue< V > > & GetRecord (const JSize index) const
 
JHashRecordT::State GetState (const JSize index) const
 
bool IsDeleted (const JSize index) const
 
bool IsFull (const JSize index) const
 
JHashValue GetHashValue (const JSize index) const
 
const JStrValue< V > & GetValue (const JSize index) const
 
void Set (const JSize index, const JHashRecord< JStrValue< V > > &record)
 
void Set (const JSize index, const JHashValue hash, const JStrValue< V > &value)
 
void Set (const JSize index, const JStrValue< V > &value)
 
void SetHash (const JSize index, const JStrValue< V > &value)
 
void Remove (const JSize index)
 
void MarkEmpty (const JSize index)
 
void MarkAllEmpty ()
 
bool TryResizeTable (const JSize lgSize)
 
void ResizeTable (const JSize lgTrialSize)
 
virtual bool FitToLimits (const JSize required=0, const bool force=false)
 
JSize HashToIndex (JHashValue hash) const
 

Detailed Description

Stores a hash table of strings for use by the program.  Each string is
associated with a unique id, which is also a string.  ID's typically
have the form "name::class".

Every application must register a unique signature.  This is used to search
for translation files:

1a. /usr/lib/<signature>/string_data/<locale>
1b. /usr/lib/<signature>/string_data/<language>
1c. /usr/lib/<signature>/string_data/default
2a. ~/.<signature>/string_data/<locale>
2b. ~/.<signature>/string_data/<language>
2c. ~/.<signature>/string_data/default

The ones that are found are loaded into the hash table in the order shown
to support overrides.

Each data file has the format:

    file format (ASCII digits followed by ASCII newline)
    # comment
    id "string"
    ...

The comment ends at the end of the line.  Inside the string, quotes and
backslashes must be preceded by a backslash.

Certain strings cannot be overridden because tampering with them
would be considered illegal.  These include VERSION, COPYRIGHT, and
LICENSE.

Menus present a special case.  If one puts the entire menu definition
into the database as a single item, then an outdated database file may
have the wrong number of menu items.  The safe solution is to store
each item's text as a separate string, keyed to the ID of the menu item.

Pseudotranslation is useful for testing layout expansion and for
catching string concatenation (which should instead be done via
parameter insertion).

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
kASCIIFormat 
kUTF8Format 

Constructor & Destructor Documentation

◆ JStringManager()

JStringManager::JStringManager ( )

◆ ~JStringManager()

JStringManager::~JStringManager ( )
override

Member Function Documentation

◆ CanOverride()

bool JStringManager::CanOverride ( const JString id)
static

◆ EnablePseudotranslation()

void JStringManager::EnablePseudotranslation ( )
inlinestatic

This must be called before initialization.

◆ Get() [1/2]

const JString & JStringManager::Get ( const JUtf8Byte id) const

◆ Get() [2/2]

JString JStringManager::Get ( const JUtf8Byte id,
const JUtf8Byte map[],
const JSize  size 
) const

Uses the given associative array to replace $ variables in the specified string and then returns the result. 'size' must be the result of sizeof(map).

◆ GetBCP47Locale()

const JString & JStringManager::GetBCP47Locale ( ) const
inline

◆ GetReplaceEngine()

JSubstitute * JStringManager::GetReplaceEngine ( ) const

Resets the replace engine and returns a pointer to it so clients can use it.

◆ MergeFile() [1/2]

bool JStringManager::MergeFile ( const JString fileName,
const bool  debug = false 
)

If debug, prints every string ID that it finds to stdout.

◆ MergeFile() [2/2]

bool JStringManager::MergeFile ( std::istream &  input,
const bool  debug = false 
)

◆ Register()

void JStringManager::Register ( const JUtf8Byte signature,
const JUtf8Byte **  defaultData 
)

We have to merge the defaults first in case the file is outdated or does not include all necessary strings.

defaultDataSize should be the result of sizeof().

◆ Replace()

void JStringManager::Replace ( JString str,
const JUtf8Byte map[],
const JSize  size 
) const

Uses the given associative array to replace $ variables in the given string. 'size' must be the result of sizeof(map).

◆ ReportError() [1/2]

void JStringManager::ReportError ( const JUtf8Byte id,
const JError err 
) const

Replaces $err in the specified string with the error message and calls JUserNotification::ReportError().

This is more helpful to the user than calling JError::ReportError()

◆ ReportError() [2/2]

void JStringManager::ReportError ( const JUtf8Byte id,
const JString message 
) const

◆ WriteFile()

void JStringManager::WriteFile ( std::ostream &  output) const

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