(file) Return to Formatter.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

  1 mike  1.11 //%/////////////////////////////////////////////////////////////////////////////
  2            //
  3            // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM
  4            //
  5            // Permission is hereby granted, free of charge, to any person obtaining a copy
  6            // of this software and associated documentation files (the "Software"), to 
  7            // deal in the Software without restriction, including without limitation the 
  8            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 
  9            // sell copies of the Software, and to permit persons to whom the Software is
 10            // furnished to do so, subject to the following conditions:
 11            // 
 12            // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN 
 13            // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 14            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 15            // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
 16            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
 17            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 
 18            // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 19            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 20            //
 21            //==============================================================================
 22 mike  1.11 //
 23            // Author: Mike Brasher (mbrasher@bmc.com)
 24            //
 25            // Modified By:
 26            //
 27            //%/////////////////////////////////////////////////////////////////////////////
 28            
 29            #include <iostream>
 30            #include <cstdio>
 31            #include "Formatter.h"
 32            
 33            PEGASUS_NAMESPACE_BEGIN
 34            
 35            String Formatter::Arg::toString() const
 36            {
 37                switch (_type)
 38                {
 39            	case INTEGER:
 40            	{
 41            	    char buffer[32];
 42            	    sprintf(buffer, "%d", _integer);
 43 mike  1.11 	    return buffer;
 44            	}
 45            
 46            	case UINTEGER:
 47            	{
 48            	    char buffer[32];
 49            	    sprintf(buffer, "%u", _integer);
 50            	    return buffer;
 51            	}
 52            
 53            	case BOOLEAN:
 54            	{
 55            	    //char buffer[32];
 56            	    //buffer = (_boolean ? "true": "false");
 57            	    //return buffer;
 58            	    return  (_boolean ? "true": "false");
 59            	}
 60            
 61            	case REAL:
 62            	{
 63            	    char buffer[32];
 64 mike  1.11 	    sprintf(buffer, "%f", _real);
 65            	    return buffer;
 66            	}
 67            
 68            	case LINTEGER:
 69            	{
 70            	    char buffer[32];
 71            	    // ATTN-B: truncation here!
 72            	    sprintf(buffer, "%ld", long(_lInteger));
 73            	    return buffer;
 74            	}
 75            	
 76            	case ULINTEGER:
 77            	{
 78            	    char buffer[32];
 79            	    // ATTN-B: truncation here:
 80            	    sprintf(buffer, "%lu", long(_lUInteger));
 81            	    return buffer;
 82            	}
 83            
 84            	case STRING:
 85 mike  1.11 	    return _string;
 86            
 87            	case VOID:
 88            	default:
 89            	    return String();
 90                }
 91            }
 92            
 93            String Formatter::format(
 94                const String& formatString,
 95                const Arg& arg0,
 96                const Arg& arg1,
 97                const Arg& arg2,
 98                const Arg& arg3,
 99                const Arg& arg4,
100                const Arg& arg5,
101                const Arg& arg6,
102                const Arg& arg7,
103                const Arg& arg8,
104                const Arg& arg9)
105            {
106 mike  1.11     String result;
107                const Char16* first = formatString.getData();
108                const Char16* last = formatString.getData() + formatString.size();
109            
110                for (; first != last; first++)
111                {
112            	if (*first == '$')
113            	{
114            	    Char16 c = *++first;
115            
116            	    switch (c)
117            	    {
118            		case '0': result += arg0.toString(); break;
119            		case '1': result += arg1.toString(); break;
120            		case '2': result += arg2.toString(); break;
121            		case '3': result += arg3.toString(); break;
122            		case '4': result += arg4.toString(); break;
123            		case '5': result += arg5.toString(); break;
124            		case '6': result += arg6.toString(); break;
125            		case '7': result += arg7.toString(); break;
126            		case '8': result += arg8.toString(); break;
127 mike  1.11 		case '9': result += arg9.toString(); break;
128            		default: break;
129            	    }
130            	}
131            	else if (*first == '\\')
132            	{
133            	    first++;
134            	    result += *first;
135            	}
136            	else
137            	    result += *first;
138                }
139            
140                return result;
141            }
142            
143            PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2