![]() ![]() |
![]() |
File: [Pegasus] / pegasus / src / Pegasus / Common / Formatter.cpp
(download)
Revision: 1.3, Wed Apr 11 06:03:02 2001 UTC (23 years, 2 months ago) by mike Branch: MAIN CVS Tags: stable Changes since 1.2: +2 -1 lines Port to Unix |
//BEGIN_LICENSE // // Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // //END_LICENSE //BEGIN_HISTORY // // Author: // // $Log: Formatter.cpp,v $ // Revision 1.3 2001/04/11 07:03:02 mike // Port to Unix // // Revision 1.1 2001/03/22 23:24:23 mike // Added new formatter class for formatting log entries and other things. // // //END_HISTORY #include <iostream> #include <cstdio> #include "Formatter.h" using namespace std; PEGASUS_NAMESPACE_BEGIN String Formatter::Arg::toString() const { switch (_type) { case INTEGER: { char buffer[32]; sprintf(buffer, "%d", _integer); return buffer; } case REAL: { char buffer[32]; sprintf(buffer, "%f", _real); return buffer; } case STRING: return _string; case VOID: default: return String(); } } String Formatter::format( const String& formatString, const Arg& arg0, const Arg& arg1, const Arg& arg2, const Arg& arg3, const Arg& arg4, const Arg& arg5, const Arg& arg6, const Arg& arg7, const Arg& arg8, const Arg& arg9) { String result; const Char16* first = formatString.getData(); const Char16* last = formatString.getData() + formatString.getLength(); for (; first != last; first++) { if (*first == '$') { Char16 c = *++first; switch (c) { case '0': result += arg0.toString(); break; case '1': result += arg1.toString(); break; case '2': result += arg2.toString(); break; case '3': result += arg3.toString(); break; case '4': result += arg4.toString(); break; case '5': result += arg5.toString(); break; case '6': result += arg6.toString(); break; case '7': result += arg7.toString(); break; case '8': result += arg8.toString(); break; case '9': result += arg9.toString(); break; default: break; } } else if (*first == '\\') { first++; result += *first; } else result += *first; } return result; } PEGASUS_NAMESPACE_END
No CVS admin address has been configured |
Powered by ViewCVS 0.9.2 |