1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is the Netscape Portable Runtime (NSPR).
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-2000
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
39 ** Class definitions to format ASCII data.
42 #if defined(_RCASCII_H)
48 ** This class maintains no state - that is the responsibility of
49 ** the class' client. For each call to Sx_printf(), the StuffFunction
50 ** will be called for each embedded "%" in the 'fmt' string and once
51 ** for each interveaning literal.
53 class PR_IMPLEMENT(RCFormatStuff)
57 virtual ~RCFormatStuff();
60 ** Process the arbitrary argument list using as indicated by
61 ** the 'fmt' string. Each segment of the processing the stuff
62 ** function is called with the relavent translation.
64 virtual PRInt32 Sx_printf(void *state, const char *fmt, ...);
67 ** The 'state' argument is not processed by the runtime. It
68 ** is merely passed from the Sx_printf() call. It is intended
69 ** to be used by the client to figure out what to do with the
72 ** The new string ('stuff') is ASCII translation driven by the
73 ** Sx_printf()'s 'fmt' string. It is not guaranteed to be a null
76 ** The return value is the number of bytes copied from the 'stuff'
77 ** string. It is accumulated for each of the calls to the stuff
78 ** function and returned from the original caller of Sx_printf().
80 virtual PRSize StuffFunction(
81 void *state, const char *stuff, PRSize stufflen) = 0;
82 }; /* RCFormatStuff */
87 ** The caller is supplying the buffer, the runtime is doing all
88 ** the conversion. The object contains no state, so is reusable
91 class PR_IMPLEMENT(RCFormatBuffer): public RCFormatStuff
95 virtual ~RCFormatBuffer();
98 ** Format the trailing arguments as indicated by the 'fmt'
99 ** string. Put the result in 'buffer'. Return the number
100 ** of bytes moved into 'buffer'. 'buffer' will always be
101 ** a properly terminated string even if the convresion fails.
103 virtual PRSize Sn_printf(
104 char *buffer, PRSize length, const char *fmt, ...);
106 virtual char *Sm_append(char *buffer, const char *fmt, ...);
110 ** This class overrides the stuff function, does not preserve
111 ** its virtual-ness and no longer allows the clients to call
112 ** it in the clear. In other words, it is now the implementation
115 PRSize StuffFunction(void*, const char*, PRSize);
117 }; /* RCFormatBuffer */
121 ** The runtime is supplying the buffer. The object has state - the
122 ** buffer. Each operation must run to completion before the object
123 ** can be reused. When it is, the buffer is reset (whatever that
124 ** means). The result of a conversion is available via the extractor.
125 ** After extracted, the memory still belongs to the class - if the
126 ** caller wants to retain or modify, it must first be copied.
128 class PR_IMPLEMENT(RCFormat): pubic RCFormatBuffer
135 ** Translate the trailing arguments according to the 'fmt'
136 ** string and store the results in the object.
138 virtual PRSize Sm_printf(const char *fmt, ...);
141 ** Extract the latest translation.
142 ** The object does not surrender the memory occupied by
143 ** the string. If the caller wishes to modify the data,
144 ** it must first be copied.
151 RCFormat(const RCFormat&);
152 RCFormat& operator=(const RCFormat&);
157 ** The output is formatted and then written to an associated file
158 ** descriptor. The client can provide a suitable file descriptor
159 ** or can indicate that the output should be directed to one of
160 ** the well-known "console" devices.
162 class PR_IMPLEMENT(RCPrint): public RCFormat
165 RCPrint(RCIO* output);
166 RCPrint(RCFileIO::SpecialFile output);
168 virtual PRSize Printf(const char *fmt, ...);
173 #endif /* defined(_RCASCII_H) */