lluistring.h

Go to the documentation of this file.
00001 
00033 #ifndef LL_LLUISTRING_H
00034 #define LL_LLUISTRING_H
00035 
00036 #include "llstring.h"
00037 #include <string>
00038 
00039 // Use this class to store translated text that may have arguments
00040 // e.g. "Welcome [USERNAME] to [SECONDLIFE]!"
00041 
00042 // Adding or changing an argument will update the result string, preserving the origianl
00043 // Thus, subsequent changes to arguments or even the original string will produce
00044 //  the correct result
00045 
00046 // Example Usage:
00047 // LLUIString mMessage("Welcome [USERNAME] to [SECONDLIFE]!");
00048 // mMessage.setArg("[USERNAME]", "Steve");
00049 // mMessage.setArg("[SECONDLIFE]", "Second Life");
00050 // llinfos << mMessage.getString().c_str() << llendl; // outputs "Welcome Steve to Second Life"
00051 // mMessage.setArg("[USERNAME]", "Joe");
00052 // llinfos << mMessage.getString().c_str() << llendl; // outputs "Welcome Joe to Second Life"
00053 // mMessage = "Recepción a la [SECONDLIFE] [USERNAME]"
00054 // mMessage.setArg("[SECONDLIFE]", "Segunda Vida");
00055 // llinfos << mMessage.getString().c_str() << llendl; // outputs "Recepción a la Segunda Vida Joe"
00056 
00057 // Implementation Notes:
00058 // Attempting to have operator[](const LLString& s) return mArgs[s] fails because we have
00059 // to call format() after the assignment happens.
00060 
00061 class LLUIString
00062 {
00063 public:
00064         // These methods all perform appropriate argument substitution
00065         // and modify mOrig where appropriate
00066         LLUIString() {}
00067         LLUIString(const LLString& instring, const LLString::format_map_t& args);
00068         LLUIString(const LLString& instring) { assign(instring); }
00069 
00070         void assign(const LLString& instring);
00071         LLUIString& operator=(const LLString& s) { assign(s); return *this; }
00072 
00073         void setArgList(const LLString::format_map_t& args);
00074         void setArg(const LLString& key, const LLString& replacement);
00075 
00076         const LLString& getString() const { return mResult; }
00077         operator LLString() const { return mResult; }
00078 
00079         const LLWString& getWString() const { return mWResult; }
00080         operator LLWString() const { return mWResult; }
00081 
00082         bool empty() const { return mWResult.empty(); }
00083         S32 length() const { return mWResult.size(); }
00084 
00085         void clear();
00086         void clearArgs() { mArgs.clear(); }
00087         
00088         // These utuilty functions are included for text editing.
00089         // They do not affect mOrig and do not perform argument substitution
00090         void truncate(S32 maxchars);
00091         void erase(S32 charidx, S32 len);
00092         void insert(S32 charidx, const LLWString& wchars);
00093         void replace(S32 charidx, llwchar wc);
00094         
00095         static const LLString::format_map_t sNullArgs;
00096 
00097 private:
00098         void format();  
00099         
00100         LLString mOrig;
00101         LLString mResult;
00102         LLWString mWResult; // for displaying
00103         LLString::format_map_t mArgs;
00104 };
00105 
00106 #endif // LL_LLUISTRING_H

Generated on Fri May 16 08:33:00 2008 for SecondLife by  doxygen 1.5.5