lluistring.h

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

Generated on Thu Jul 1 06:09:24 2010 for Second Life Viewer by  doxygen 1.4.7