WxExtLib - WxMessageFormat.cpp
00001:
00002: /*
00003: -------------------------------------------------------------------------
00004: This file is part of WxWidgetsExtensions library.
00005: -------------------------------------------------------------------------
00006:
00007: WxExtLib (WxWidgetsExtensions) library
00008: -----------------------------
00009:
00010: COPYRIGHT NOTICE:
00011:
00012: WxExtLib library Copyright (c) 2003-2007 Daniel Käps
00013:
00014: The WxWidgetsExtensions library and associated documentation files (the
00015: "Software") is provided "AS IS". The author(s) disclaim all
00016: warranties, expressed or implied, including, without limitation, the
00017: warranties of merchantability and of fitness for any purpose. The
00018: author(s) assume no liability for direct, indirect, incidental,
00019: special, exemplary, or consequential damages, which may result from
00020: the use of or other dealings in the Software, even if advised of the
00021: possibility of such damage.
00022:
00023: Permission is hereby granted, free of charge, to any person obtaining
00024: a copy of this Software, to deal in the Software without restriction,
00025: including without limitation the rights to use, copy, modify, merge,
00026: publish, distribute, sublicense, and/or sell copies of the Software,
00027: and to permit persons to whom the Software is furnished to do so,
00028: subject to the following conditions:
00029:
00030: 1. The origin of this source code must not be misrepresented.
00031: 2. Altered versions must be plainly marked as such and must not be
00032: misrepresented as being the original source.
00033: 3. This Copyright notice may not be removed or altered from any
00034: source or altered source distribution.
00035:
00036: End of WxExtLib library Copyright Notice
00037:
00038: -------------------------------------------------------------------------
00039: */
00040:
00041: //-------------------------------------------------------------------------
00042: //
00043: // NOTE
00044: //
00045: // - WxMessageFormat.h,.cpp files are superseeded by StxFormatMessage.h,.cpp.
00046: // Development and changes shall be made to StxFormatMessage.h,.cpp
00047: // (not yet published).
00048: //
00049: //-------------------------------------------------------------------------
00050:
00051: //=========================================================================
00052:
00053: #ifdef M_MessageFormat_IsUseStxFormatMessage
00054:
00055: # include <StxFormatMessage.h>
00056: # include <StxFormatMessage.cpp>
00057:
00058: //=========================================================================
00059:
00060: #else
00061:
00062: #if (!defined M_MessageFormat_IsEmitImplementation)
00063:
00064: //-------------------------------------------------------------------------
00065:
00066: #if ((!defined M_MessageFormat_WxString) && (!defined M_MessageFormat_StdString))
00067: # error "please define at least one of M_MessageFormat_StdString, M_MessageFormat_WxString"
00068: #endif
00069:
00070: //-------------------------------------------------------------------------
00071:
00072: // wxString interface: wxMessageFormatter, wxFormat, etc.
00073: // using wxString
00074:
00075: #if (defined M_MessageFormat_WxString)
00076:
00077: #ifndef _IMPLEMENTED_MessageFormat_WxString
00078: #define _IMPLEMENTED_MessageFormat_WxString
00079:
00080: #define M_MessageFormat_IsEmitImplementation
00081: #define M_MessageFormat_IsUseWxString 1
00082: #define M_MessageFormatter wxMessageFormatter
00083: #define M_Format wxFormat
00084: #define M_FormatMessage wxFormatMessage
00085: #define M_String wxString
00086: #define M_FormatArray wxFormatArray
00087: #define M_makeMessageFormatter MessageFormatter
00088: #include "WxMessageFormat.cpp"
00089: #undef M_MessageFormat_IsEmitImplementation
00090: #undef M_MessageFormat_IsUseWxString
00091: #undef M_MessageFormatter
00092: #undef M_Format
00093: #undef M_FormatMessage
00094: #undef M_String
00095: #undef M_FormatArray
00096: #undef M_makeMessageFormatter
00097:
00098: #endif
00099:
00100: #endif
00101:
00102: //-------------------------------------------------------------------------
00103:
00104: // std::string interface: stMessageFormatter, stFormat, etc.
00105: // using std::string
00106:
00107: #if (defined M_MessageFormat_StdString)
00108:
00109: #ifndef _IMPLEMENTED_MessageFormat_StdString
00110: #define _IMPLEMENTED_MessageFormat_StdString
00111:
00112: #define M_MessageFormat_IsEmitImplementation
00113: #define M_MessageFormat_IsUseStdString 1
00114: #define M_MessageFormatter stMessageFormatter
00115: #define M_Format stFormat
00116: #define M_FormatMessage stFormatMessage
00117: #define M_String std::string
00118: #define M_FormatArray stFormatArray
00119: #define M_makeMessageFormatter makeStdStringMessageFormatter
00120: #include "WxMessageFormat.cpp"
00121: #undef M_MessageFormat_IsEmitImplementation
00122: #undef M_MessageFormat_IsUseStdString
00123: #undef M_MessageFormatter
00124: #undef M_Format
00125: #undef M_FormatMessage
00126: #undef M_String
00127: #undef M_FormatArray
00128: #undef M_makeMessageFormatter
00129:
00130: #endif
00131:
00132: #endif
00133:
00134: //-------------------------------------------------------------------------
00135:
00136: #endif // (!defined M_MessageFormat_IsEmitImplemenation)
00137:
00138: //=========================================================================
00139:
00140:
00141: #if (defined M_MessageFormat_IsEmitImplementation)
00142:
00143: //-------------------------------------------------------------------------
00144:
00145: // inclusion of basic headers:
00146:
00147: // WARN it is not clear how the multiple variations of this file
00148: // interact with "#pragma interface"
00149: // #if defined(__GNUG__) && (!defined(__APPLE__)) && (!(defined M_NoPragmaInterface))
00150: // #pragma implementation "WxMessageFormat.cpp"
00151: // #endif
00152:
00153: #if (M_MessageFormat_IsUseWxString == 1)
00154: #include "WxExtLibConfig.h"
00155:
00156: // For compilers that support precompilation, includes "wx/wx.h".
00157: #include "wx/wxprec.h"
00158:
00159: #ifdef __BORLANDC__
00160: #pragma hdrstop
00161: #endif
00162: #endif
00163:
00164: #if (M_MessageFormat_IsUseStdString == 1)
00165: # include <string>
00166: #endif
00167:
00168: //-------------------------------------------------------------------------
00169:
00170: // message format declarations:
00171: #include "WxMessageFormat.h"
00172:
00173: #include "safecast.h"
00174:
00175: #ifdef M_MessageFormat_IsTraceUsedInterface
00176: # if (M_MessageFormat_IsUseWxString == 1)
00177: # pragma message ("-- wxFormatMessage() etc. / wxString implementation")
00178: # endif
00179: # if (M_MessageFormat_IsUseStdString == 1)
00180: # pragma message ("-- stFormatMessage() etc. / std::string implementation")
00181: # endif
00182: #endif
00183:
00184: //=========================================================================
00185:
00186: M_Format::M_Format (int Integer)
00187: {
00188: init ("%d", Integer);
00189: }
00190:
00191: M_Format::M_Format (const char * PrintfFormatString, int Integer)
00192: {
00193: init (PrintfFormatString, Integer);
00194: }
00195:
00196: M_Format::M_Format (unsigned int UInt)
00197: {
00198: init ("%u", UInt);
00199: }
00200:
00201: M_Format::M_Format (const char * PrintfFormatString, unsigned int UInt)
00202: {
00203: init (PrintfFormatString, UInt);
00204: }
00205:
00206: M_Format::M_Format (long Long)
00207: {
00208: init ("%ld", Long);
00209: }
00210:
00211: M_Format::M_Format (const char * PrintfFormatString, long Long)
00212: {
00213: init (PrintfFormatString, Long);
00214: }
00215:
00216: M_Format::M_Format (unsigned long ULong)
00217: {
00218: init ("%lu", ULong);
00219: }
00220:
00221: M_Format::M_Format (const char * PrintfFormatString, unsigned long ULong)
00222: {
00223: init (PrintfFormatString, ULong);
00224: }
00225:
00226: M_Format::M_Format (const float & Float)
00227: {
00228: init ("%f", Float);
00229: }
00230:
00231: M_Format::M_Format (const char * PrintfFormatString, const float & Float)
00232: {
00233: double Double = Float;
00234: init (PrintfFormatString, Double);
00235: }
00236:
00237: M_Format::M_Format (const double & Double)
00238: {
00239: init ("%f", Double);
00240: }
00241:
00242: M_Format::M_Format (const char * PrintfFormatString, const double & Double)
00243: {
00244: init (PrintfFormatString, Double);
00245: }
00246:
00247: M_Format::M_Format (const char * CharPtr)
00248: {
00249: init ("%s", CharPtr);
00250: }
00251:
00252: M_Format::M_Format (const char * PrintfFormatString, const char * CharPtr)
00253: {
00254: init (PrintfFormatString, CharPtr);
00255: }
00256:
00257: M_Format::M_Format (const M_String & String)
00258: {
00259: init ("%s", String);
00260: }
00261:
00262: M_Format::M_Format (const char * PrintfFormatString, const M_String & String)
00263: {
00264: init (PrintfFormatString, String);
00265: }
00266:
00267: M_Format::M_Format (char Char)
00268: {
00269: init ("%c", Char);
00270: }
00271:
00272: M_Format::M_Format (const char * PrintfFormatString, char Char)
00273: {
00274: init (PrintfFormatString, Char);
00275: }
00276:
00277: M_Format::M_Format (unsigned char UChar)
00278: {
00279: init ("%c", UChar);
00280: }
00281:
00282: M_Format::M_Format (const char * PrintfFormatString, unsigned char UChar)
00283: {
00284: init (PrintfFormatString, UChar);
00285: }
00286:
00287: //-------------------------------------------------------------------------
00288:
00289: M_Format::~M_Format ()
00290: {
00291: }
00292:
00293: //-------------------------------------------------------------------------
00294:
00295: // temporary macro for calls to printf
00296: #if (M_MessageFormat_IsUseWxString == 1)
00297:
00298: // wxString has a member function Printf() for our needs
00299: #define M_PrintfHelper(PrintfFormatString, Value, BufferSize) \
00300: m_FormattedValueString.Printf (PrintfFormatString, Value);
00301:
00302: #elif (M_MessageFormat_IsUseStdString == 1)
00303:
00304: #define M_PrintfHelper(PrintfFormatString, Value, BufferSize) \
00305: char TempCharArray[BufferSize]; \
00306: TempCharArray[0] = '\0'; \
00307: sprintf (TempCharArray, PrintfFormatString, Value); \
00308: TempCharArray[BufferSize - 1] = '\0'; \
00309: m_FormattedValueString.append (TempCharArray);
00310:
00311: #else
00312: #error "unhandled/missing implementation of M_PrintfHelper macro"
00313:
00314: #endif
00315:
00316: //-------------------------------------------------------------------------
00317:
00318: void M_Format::init (const char * PrintfFormatString, int Integer)
00319: {
00320: M_PrintfHelper (PrintfFormatString, Integer, 20);
00321: }
00322:
00323: void M_Format::init (const char * PrintfFormatString, unsigned int UInt)
00324: {
00325: M_PrintfHelper (PrintfFormatString, UInt, 20);
00326: }
00327:
00328: void M_Format::init (const char * PrintfFormatString, long Long)
00329: {
00330: M_PrintfHelper (PrintfFormatString, Long, 32);
00331: }
00332:
00333: void M_Format::init (const char * PrintfFormatString, unsigned long ULong)
00334: {
00335: M_PrintfHelper (PrintfFormatString, ULong, 32);
00336: }
00337:
00338: void M_Format::init (const char * PrintfFormatString, const double & Double)
00339: {
00340: // WARN what is the maximum number of characters printed for
00341: // double-precision floating point according to output format?
00342: M_PrintfHelper (PrintfFormatString, Double, 1024);
00343: }
00344:
00345: void M_Format::init (const char * PrintfFormatString, const char * CharPtr)
00346: {
00347: #if (M_MessageFormat_IsUseWxString == 1)
00348: m_FormattedValueString.Printf (PrintfFormatString, CharPtr);
00349: #elif (M_MessageFormat_IsUseStdString == 1)
00350: // HACK NOTE: PrintfFormatString is ignored for String arguments
00351: m_FormattedValueString.append (CharPtr);
00352: #else
00353: #error "unhandled/missing handling of string formatting"
00354: #endif
00355: }
00356:
00357: void M_Format::init (const char * PrintfFormatString, const M_String & String)
00358: {
00359: #if (M_MessageFormat_IsUseWxString == 1)
00360: m_FormattedValueString.Printf (PrintfFormatString, String.c_str());
00361: #elif (M_MessageFormat_IsUseStdString == 1)
00362: // HACK NOTE: PrintfFormatString is ignored for String arguments
00363: m_FormattedValueString.append (String.c_str());
00364: #else
00365: #error "unhandled/missing string formatting"
00366: #endif
00367: }
00368:
00369: void M_Format::init (const char * PrintfFormatString, char Char)
00370: {
00371: M_PrintfHelper (PrintfFormatString, Char, 4);
00372: }
00373:
00374: void M_Format::init (const char * PrintfFormatString, unsigned char UChar)
00375: {
00376: M_PrintfHelper (PrintfFormatString, UChar, 4);
00377: }
00378:
00379: void M_Format::appendTo (M_String & String) const
00380: {
00381: String += m_FormattedValueString;
00382: }
00383:
00384: #undef M_PrintfHelper
00385:
00386: //=========================================================================
00387:
00388: M_String M_FormatMessage (const char * FormatString)
00389: {
00390: M_MessageFormatter MessageFormatter_ (FormatString);
00391:
00392: return MessageFormatter_.getRef();
00393: }
00394:
00395: M_String M_FormatMessage (const char * FormatString, const M_Format & Param1Format)
00396: {
00397: M_MessageFormatter MessageFormatter_ (FormatString);
00398: MessageFormatter_ % Param1Format;
00399:
00400: return MessageFormatter_.getRef();
00401: }
00402:
00403: M_String M_FormatMessage (const char * FormatString,
00404: const M_Format & Param1Format,
00405: const M_Format & Param2Format)
00406: {
00407: M_MessageFormatter MessageFormatter_ (FormatString);
00408: MessageFormatter_
00409: % Param1Format
00410: % Param2Format;
00411:
00412: return MessageFormatter_.getRef();
00413: }
00414:
00415: M_String M_FormatMessage (const char * FormatString,
00416: const M_Format & Param1Format,
00417: const M_Format & Param2Format,
00418: const M_Format & Param3Format)
00419: {
00420: M_MessageFormatter MessageFormatter_ (FormatString);
00421: MessageFormatter_
00422: % Param1Format
00423: % Param2Format
00424: % Param3Format;
00425:
00426: return MessageFormatter_.getRef();
00427: }
00428:
00429: M_String M_FormatMessage (const char * FormatString,
00430: const M_Format & Param1Format,
00431: const M_Format & Param2Format,
00432: const M_Format & Param3Format,
00433: const M_Format & Param4Format)
00434: {
00435: M_MessageFormatter MessageFormatter_ (FormatString);
00436: MessageFormatter_
00437: % Param1Format
00438: % Param2Format
00439: % Param3Format
00440: % Param4Format;
00441:
00442: return MessageFormatter_.getRef();
00443: }
00444:
00445: M_String M_FormatMessage (const char * FormatString,
00446: const M_Format & Param1Format,
00447: const M_Format & Param2Format,
00448: const M_Format & Param3Format,
00449: const M_Format & Param4Format,
00450: const M_Format & Param5Format)
00451: {
00452: M_MessageFormatter MessageFormatter_ (FormatString);
00453: MessageFormatter_
00454: % Param1Format
00455: % Param2Format
00456: % Param3Format
00457: % Param4Format
00458: % Param5Format;
00459:
00460: return MessageFormatter_.getRef();
00461: }
00462:
00463: M_String M_FormatMessage (const char * FormatString,
00464: const M_Format & Param1Format,
00465: const M_Format & Param2Format,
00466: const M_Format & Param3Format,
00467: const M_Format & Param4Format,
00468: const M_Format & Param5Format,
00469: const M_Format & Param6Format)
00470: {
00471: M_MessageFormatter MessageFormatter_ (FormatString);
00472: MessageFormatter_
00473: % Param1Format
00474: % Param2Format
00475: % Param3Format
00476: % Param4Format
00477: % Param5Format
00478: % Param6Format;
00479:
00480: return MessageFormatter_.getRef();
00481: }
00482:
00483: M_String M_FormatMessage (const char * FormatString,
00484: const M_Format & Param1Format,
00485: const M_Format & Param2Format,
00486: const M_Format & Param3Format,
00487: const M_Format & Param4Format,
00488: const M_Format & Param5Format,
00489: const M_Format & Param6Format,
00490: const M_Format & Param7Format)
00491: {
00492: M_MessageFormatter MessageFormatter_ (FormatString);
00493: MessageFormatter_
00494: % Param1Format
00495: % Param2Format
00496: % Param3Format
00497: % Param4Format
00498: % Param5Format
00499: % Param6Format
00500: % Param7Format;
00501:
00502: return MessageFormatter_.getRef();
00503: }
00504: M_String M_FormatMessage (const char * FormatString,
00505: const M_Format & Param1Format,
00506: const M_Format & Param2Format,
00507: const M_Format & Param3Format,
00508: const M_Format & Param4Format,
00509: const M_Format & Param5Format,
00510: const M_Format & Param6Format,
00511: const M_Format & Param7Format,
00512: const M_Format & Param8Format)
00513: {
00514: M_MessageFormatter MessageFormatter_ (FormatString);
00515: MessageFormatter_
00516: % Param1Format
00517: % Param2Format
00518: % Param3Format
00519: % Param4Format
00520: % Param5Format
00521: % Param6Format
00522: % Param7Format
00523: % Param8Format;
00524:
00525: return MessageFormatter_.getRef();
00526: }
00527: M_String M_FormatMessage (const char * FormatString,
00528: const M_Format & Param1Format,
00529: const M_Format & Param2Format,
00530: const M_Format & Param3Format,
00531: const M_Format & Param4Format,
00532: const M_Format & Param5Format,
00533: const M_Format & Param6Format,
00534: const M_Format & Param7Format,
00535: const M_Format & Param8Format,
00536: const M_Format & Param9Format)
00537: {
00538: M_MessageFormatter MessageFormatter_ (FormatString);
00539: MessageFormatter_
00540: % Param1Format
00541: % Param2Format
00542: % Param3Format
00543: % Param4Format
00544: % Param5Format
00545: % Param6Format
00546: % Param7Format
00547: % Param8Format
00548: % Param9Format;
00549:
00550: return MessageFormatter_.getRef();
00551: }
00552: M_String M_FormatMessage (const char * FormatString,
00553: const M_Format & Param1Format,
00554: const M_Format & Param2Format,
00555: const M_Format & Param3Format,
00556: const M_Format & Param4Format,
00557: const M_Format & Param5Format,
00558: const M_Format & Param6Format,
00559: const M_Format & Param7Format,
00560: const M_Format & Param8Format,
00561: const M_Format & Param9Format,
00562: const M_Format & Param10Format)
00563: {
00564: M_MessageFormatter MessageFormatter_ (FormatString);
00565: MessageFormatter_
00566: % Param1Format
00567: % Param2Format
00568: % Param3Format
00569: % Param4Format
00570: % Param5Format
00571: % Param6Format
00572: % Param7Format
00573: % Param8Format
00574: % Param9Format
00575: % Param10Format;
00576:
00577: return MessageFormatter_.getRef();
00578: }
00579:
00580: //=========================================================================
00581:
00582: M_MessageFormatter M_makeMessageFormatter (const char * FormatString)
00583: {
00584: return M_MessageFormatter (FormatString);
00585: }
00586:
00587: //-------------------------------------------------------------------------
00588:
00589: M_String & operator+= (M_String & String, M_MessageFormatter & MessageFormatter)
00590: {
00591: MessageFormatter.appendTo (String);
00592: return String;
00593: }
00594:
00595: //-------------------------------------------------------------------------
00596:
00597: M_MessageFormatter::M_MessageFormatter (const char * FormatString)
00598: {
00599: m_FormatString = FormatString;
00600: }
00601:
00602: M_MessageFormatter::~M_MessageFormatter ()
00603: {
00604: #if (M_MessageFormat_IsUseWxString == 1)
00605: int FormatCount = m_FormatArray.GetCount();
00606: #elif (M_MessageFormat_IsUseStdString == 1)
00607: int FormatCount = m_FormatArray.size();
00608: #else
00609: #error "missing implementation to obtain array size of M_FormatArray"
00610: #endif
00611:
00612: for (int FormatIndex=0; FormatIndex<FormatCount; ++FormatIndex)
00613: {
00614: delete m_FormatArray[FormatIndex];
00615: m_FormatArray[FormatIndex] = NULL;
00616: }
00617: }
00618:
00619: //-------------------------------------------------------------------------
00620:
00621: #if 0 // TEST commented out - see comment in header
00622: M_MessageFormatter & M_MessageFormatter::operator% (int Integer)
00623: {
00624: addFormat (new M_Format (Integer));
00625: return *this;
00626: }
00627:
00628: M_MessageFormatter & M_MessageFormatter::operator% (long Long)
00629: {
00630: addFormat (new M_Format (Long));
00631: return *this;
00632: }
00633:
00634: M_MessageFormatter & M_MessageFormatter::operator% (const double & Double)
00635: {
00636: addFormat (new M_Format (Double));
00637: return *this;
00638: }
00639:
00640: M_MessageFormatter & M_MessageFormatter::operator% (const char * CharPtr)
00641: {
00642: addFormat (new M_Format (CharPtr));
00643: return *this;
00644: }
00645:
00646: M_MessageFormatter & M_MessageFormatter::operator% (const M_String & String)
00647: {
00648: addFormat (new M_Format (String));
00649: return *this;
00650: }
00651: #endif
00652:
00653: M_MessageFormatter & M_MessageFormatter::operator% (const M_Format & Format)
00654: {
00655: addFormat (new M_Format (Format));
00656: return *this;
00657: }
00658:
00659: M_MessageFormatter & M_MessageFormatter::operator% (M_Format * FormatPtr)
00660: {
00661: addFormat (FormatPtr);
00662: return *this;
00663: }
00664:
00665: //-------------------------------------------------------------------------
00666:
00667: M_MessageFormatter & M_MessageFormatter::addFormat (M_Format * FormatPtr)
00668: {
00669: #if (M_MessageFormat_IsUseWxString == 1)
00670: m_FormatArray.Add (FormatPtr);
00671: #elif (M_MessageFormat_IsUseStdString == 1)
00672: m_FormatArray.push_back (FormatPtr);
00673: #else
00674: #error "addFormat(): unhandled/missing array addition"
00675: #endif
00676: return *this;
00677: }
00678:
00679: //-------------------------------------------------------------------------
00680:
00681: void M_MessageFormatter::format ()
00682: {
00683: #if (M_MessageFormat_IsUseWxString == 1)
00684: int FormatStringCharCount = m_FormatString.Length();
00685: #elif (M_MessageFormat_IsUseStdString == 1)
00686: int FormatStringCharCount = m_FormatString.length();
00687: #else
00688: #error "missing implementation to obtain string length of M_FormatString"
00689: #endif
00690: bool IsPreviousCharPercentChar = false;
00691:
00692: int FormatIndex = 0;
00693:
00694: for (int FormatStringCharIndex=0;
00695: FormatStringCharIndex < FormatStringCharCount;
00696: ++FormatStringCharIndex)
00697: {
00698: const char * FormatStringCharPtr = & (m_FormatString.c_str() [FormatStringCharIndex]);
00699:
00700: if (IsPreviousCharPercentChar)
00701: {
00702: if (*FormatStringCharPtr == '%')
00703: {
00704: m_OutputString += '%';
00705: }
00706: else if (isdigit (*FormatStringCharPtr)
00707: || (*FormatStringCharPtr == '+')
00708: || (*FormatStringCharPtr == '{'))
00709: {
00710: bool IsParsed = false;
00711: if (*FormatStringCharPtr == '+')
00712: {
00713: // used syntax is "%+"
00714: ++FormatIndex;
00715: IsParsed = true;
00716: }
00717: else if (*FormatStringCharPtr == '{')
00718: {
00719: // used syntax is "%{N}" (e.g. "%{12}", "%{5}"
00720: int ParsedCharacterCount = 0;
00721: if (sscanf (FormatStringCharPtr + 1, "%d%n",
00722: & FormatIndex,
00723: & ParsedCharacterCount) >= 1)
00724: {
00725: IsParsed = true;
00726:
00727: FormatStringCharIndex += ParsedCharacterCount;
00728: if (FormatStringCharPtr [ParsedCharacterCount + 1] == '}')
00729: {
00730: ++FormatStringCharIndex;
00731: }
00732: }
00733: }
00734: else if (isdigit (*FormatStringCharPtr))
00735: {
00736: // used syntax is "%N" (single digit, e.g. "%2")
00737: FormatIndex = ((int) *FormatStringCharPtr) - '0';
00738: IsParsed = true;
00739: }
00740:
00741: if (IsParsed)
00742: {
00743: if (FormatIndex > 0
00744: && cast_is_equal_smaller (FormatIndex,
00745: #if (M_MessageFormat_IsUseWxString == 1)
00746: m_FormatArray.GetCount()))
00747: #elif (M_MessageFormat_IsUseStdString == 1)
00748: m_FormatArray.size()))
00749: #else
00750: #error "missing implementation to obtain size of M_FormatArray"
00751: #endif
00752: {
00753: m_FormatArray[FormatIndex-1] -> appendTo (m_OutputString);
00754: }
00755: else
00756: {
00757: m_OutputString += "[??]";
00758: // TODO: could add logging if argument is missing
00759: }
00760: }
00761: }
00762: IsPreviousCharPercentChar = false;
00763: }
00764: else
00765: {
00766: if (*FormatStringCharPtr != '%')
00767: m_OutputString += *FormatStringCharPtr;
00768:
00769: IsPreviousCharPercentChar = *FormatStringCharPtr == '%';
00770: }
00771: }
00772: }
00773:
00774: //-------------------------------------------------------------------------
00775:
00776: const M_String & M_MessageFormatter::getRef ()
00777: {
00778: format ();
00779: return m_OutputString;
00780: }
00781:
00782: M_MessageFormatter::operator const M_String & ()
00783: {
00784: format ();
00785: return m_OutputString;
00786: }
00787:
00788: M_MessageFormatter::operator const char * ()
00789: {
00790: format ();
00791: return m_OutputString.c_str();
00792: }
00793:
00794: //-------------------------------------------------------------------------
00795:
00796: void M_MessageFormatter::appendTo (M_String & String)
00797: {
00798: String += operator const M_String & ();
00799: }
00800:
00801: void M_MessageFormatter::assignTo (M_String & String)
00802: {
00803: String = operator const M_String & ();
00804: }
00805:
00806: //=========================================================================
00807:
00808: #endif // (defined M_MessageFormat_IsEmitImplementation)
00809:
00810: //=========================================================================
00811:
00812: #endif /* M_MessageFormat_IsUseStxFormatMessage */
00813:
00814: //=========================================================================
00815: