Wed, 31 Dec 2014 06:55:46 +0100
Added tag TORBROWSER_REPLICA for changeset 6474c204b198
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | /* |
michael@0 | 7 | ** Class definitions to format ASCII data. |
michael@0 | 8 | */ |
michael@0 | 9 | |
michael@0 | 10 | #if defined(_RCASCII_H) |
michael@0 | 11 | #else |
michael@0 | 12 | #define _RCASCII_H |
michael@0 | 13 | |
michael@0 | 14 | /* |
michael@0 | 15 | ** RCFormatStuff |
michael@0 | 16 | ** This class maintains no state - that is the responsibility of |
michael@0 | 17 | ** the class' client. For each call to Sx_printf(), the StuffFunction |
michael@0 | 18 | ** will be called for each embedded "%" in the 'fmt' string and once |
michael@0 | 19 | ** for each interveaning literal. |
michael@0 | 20 | */ |
michael@0 | 21 | class PR_IMPLEMENT(RCFormatStuff) |
michael@0 | 22 | { |
michael@0 | 23 | public: |
michael@0 | 24 | RCFormatStuff(); |
michael@0 | 25 | virtual ~RCFormatStuff(); |
michael@0 | 26 | |
michael@0 | 27 | /* |
michael@0 | 28 | ** Process the arbitrary argument list using as indicated by |
michael@0 | 29 | ** the 'fmt' string. Each segment of the processing the stuff |
michael@0 | 30 | ** function is called with the relavent translation. |
michael@0 | 31 | */ |
michael@0 | 32 | virtual PRInt32 Sx_printf(void *state, const char *fmt, ...); |
michael@0 | 33 | |
michael@0 | 34 | /* |
michael@0 | 35 | ** The 'state' argument is not processed by the runtime. It |
michael@0 | 36 | ** is merely passed from the Sx_printf() call. It is intended |
michael@0 | 37 | ** to be used by the client to figure out what to do with the |
michael@0 | 38 | ** new string. |
michael@0 | 39 | ** |
michael@0 | 40 | ** The new string ('stuff') is ASCII translation driven by the |
michael@0 | 41 | ** Sx_printf()'s 'fmt' string. It is not guaranteed to be a null |
michael@0 | 42 | ** terminated string. |
michael@0 | 43 | ** |
michael@0 | 44 | ** The return value is the number of bytes copied from the 'stuff' |
michael@0 | 45 | ** string. It is accumulated for each of the calls to the stuff |
michael@0 | 46 | ** function and returned from the original caller of Sx_printf(). |
michael@0 | 47 | */ |
michael@0 | 48 | virtual PRSize StuffFunction( |
michael@0 | 49 | void *state, const char *stuff, PRSize stufflen) = 0; |
michael@0 | 50 | }; /* RCFormatStuff */ |
michael@0 | 51 | |
michael@0 | 52 | |
michael@0 | 53 | /* |
michael@0 | 54 | ** RCFormatBuffer |
michael@0 | 55 | ** The caller is supplying the buffer, the runtime is doing all |
michael@0 | 56 | ** the conversion. The object contains no state, so is reusable |
michael@0 | 57 | ** and reentrant. |
michael@0 | 58 | */ |
michael@0 | 59 | class PR_IMPLEMENT(RCFormatBuffer): public RCFormatStuff |
michael@0 | 60 | { |
michael@0 | 61 | public: |
michael@0 | 62 | RCFormatBuffer(); |
michael@0 | 63 | virtual ~RCFormatBuffer(); |
michael@0 | 64 | |
michael@0 | 65 | /* |
michael@0 | 66 | ** Format the trailing arguments as indicated by the 'fmt' |
michael@0 | 67 | ** string. Put the result in 'buffer'. Return the number |
michael@0 | 68 | ** of bytes moved into 'buffer'. 'buffer' will always be |
michael@0 | 69 | ** a properly terminated string even if the convresion fails. |
michael@0 | 70 | */ |
michael@0 | 71 | virtual PRSize Sn_printf( |
michael@0 | 72 | char *buffer, PRSize length, const char *fmt, ...); |
michael@0 | 73 | |
michael@0 | 74 | virtual char *Sm_append(char *buffer, const char *fmt, ...); |
michael@0 | 75 | |
michael@0 | 76 | private: |
michael@0 | 77 | /* |
michael@0 | 78 | ** This class overrides the stuff function, does not preserve |
michael@0 | 79 | ** its virtual-ness and no longer allows the clients to call |
michael@0 | 80 | ** it in the clear. In other words, it is now the implementation |
michael@0 | 81 | ** for this class. |
michael@0 | 82 | */ |
michael@0 | 83 | PRSize StuffFunction(void*, const char*, PRSize); |
michael@0 | 84 | |
michael@0 | 85 | }; /* RCFormatBuffer */ |
michael@0 | 86 | |
michael@0 | 87 | /* |
michael@0 | 88 | ** RCFormat |
michael@0 | 89 | ** The runtime is supplying the buffer. The object has state - the |
michael@0 | 90 | ** buffer. Each operation must run to completion before the object |
michael@0 | 91 | ** can be reused. When it is, the buffer is reset (whatever that |
michael@0 | 92 | ** means). The result of a conversion is available via the extractor. |
michael@0 | 93 | ** After extracted, the memory still belongs to the class - if the |
michael@0 | 94 | ** caller wants to retain or modify, it must first be copied. |
michael@0 | 95 | */ |
michael@0 | 96 | class PR_IMPLEMENT(RCFormat): pubic RCFormatBuffer |
michael@0 | 97 | { |
michael@0 | 98 | public: |
michael@0 | 99 | RCFormat(); |
michael@0 | 100 | virtual ~RCFormat(); |
michael@0 | 101 | |
michael@0 | 102 | /* |
michael@0 | 103 | ** Translate the trailing arguments according to the 'fmt' |
michael@0 | 104 | ** string and store the results in the object. |
michael@0 | 105 | */ |
michael@0 | 106 | virtual PRSize Sm_printf(const char *fmt, ...); |
michael@0 | 107 | |
michael@0 | 108 | /* |
michael@0 | 109 | ** Extract the latest translation. |
michael@0 | 110 | ** The object does not surrender the memory occupied by |
michael@0 | 111 | ** the string. If the caller wishes to modify the data, |
michael@0 | 112 | ** it must first be copied. |
michael@0 | 113 | */ |
michael@0 | 114 | const char*(); |
michael@0 | 115 | |
michael@0 | 116 | private: |
michael@0 | 117 | char *buffer; |
michael@0 | 118 | |
michael@0 | 119 | RCFormat(const RCFormat&); |
michael@0 | 120 | RCFormat& operator=(const RCFormat&); |
michael@0 | 121 | }; /* RCFormat */ |
michael@0 | 122 | |
michael@0 | 123 | /* |
michael@0 | 124 | ** RCPrint |
michael@0 | 125 | ** The output is formatted and then written to an associated file |
michael@0 | 126 | ** descriptor. The client can provide a suitable file descriptor |
michael@0 | 127 | ** or can indicate that the output should be directed to one of |
michael@0 | 128 | ** the well-known "console" devices. |
michael@0 | 129 | */ |
michael@0 | 130 | class PR_IMPLEMENT(RCPrint): public RCFormat |
michael@0 | 131 | { |
michael@0 | 132 | virtual ~RCPrint(); |
michael@0 | 133 | RCPrint(RCIO* output); |
michael@0 | 134 | RCPrint(RCFileIO::SpecialFile output); |
michael@0 | 135 | |
michael@0 | 136 | virtual PRSize Printf(const char *fmt, ...); |
michael@0 | 137 | private: |
michael@0 | 138 | RCPrint(); |
michael@0 | 139 | }; /* RCPrint */ |
michael@0 | 140 | |
michael@0 | 141 | #endif /* defined(_RCASCII_H) */ |
michael@0 | 142 | |
michael@0 | 143 | /* RCAscii.h */ |