4
Copyright (C) 1995, 1996 Ovidiu Predescu and Mircea Oancea.
7
Author: Ovidiu Predescu <ovidiu@bx.logicnet.ro>
9
This file is part of libFoundation.
11
Permission to use, copy, modify, and distribute this software and its
12
documentation for any purpose and without fee is hereby granted, provided
13
that the above copyright notice appear in all copies and that both that
14
copyright notice and this permission notice appear in supporting
17
We disclaim all warranties with regard to this software, including all
18
implied warranties of merchantability and fitness, in no event shall
19
we be liable for any special, indirect or consequential damages or any
20
damages whatsoever resulting from loss of use, data or profits, whether in
21
an action of contract, negligence or other tortious action, arising out of
22
or in connection with the use or performance of this software.
25
#ifndef __FormatScanner_h__
26
#define __FormatScanner_h__
29
#include <Foundation/NSObject.h>
34
* A FormatScanner scans a NSString format. When it reaches a specifier
35
* similar to printf(3S), it calls a handler object previously registered to
36
* it. The handler object is usually inherited from the DefaultScannerHandler
37
* class. The handler object maintains a mapping between format characters and
38
* selectors that have to be called when a specifier is found in the format
39
* string. The selector must have exactly two arguments: the first one is a
40
* pointer to a va_list and the second one is the format scanner. It is the
41
* responsability of handler to increase the pointer to the va_list with the
42
* size of the object it handles. During the execution of the method the
43
* scanner calls, the handler can ask the scanner about the flags, width,
44
* precision, modifiers and the specifier character. The method should return a
45
* NSString object that represents the converted object.
47
* FormatScanner is an abstract class. Use the PrintfFormatScanner class that
48
* is used to write printf-like functions. Additional classes can be inherited
49
* to write scanf-like functions.
53
FS_ALTERNATE_FORM = 1,
60
@interface FormatScanner : NSObject
62
int specifierLen, specifierSize;
63
char *currentSpecifier;
69
char characterSpecifier;
73
BOOL allowPrecision:1;
77
/* This method start the searching of specifiers in `format'. `context' is
78
passed in handleFormatSpecifierWithContext: unmodified. */
79
- (BOOL)parseFormatString:(NSString*)format context:(void*)context;
81
/* This method is called whenever a string between two specifiers is found.
82
Rewrite it in subclasses to perform whatever action you want (for example
83
to collect them in a result string if you're doing printf). The method
84
should return NO if the scanning of format should stop. */
85
- (BOOL)handleOrdinaryString:(NSString*)string;
87
/* This method is called whenever a format specifier is found in `format'.
88
Again, rewrite this method in subclasses to perform whatever action you
89
want. The method should return NO if the scanning of the format should stop.
91
- (BOOL)handleFormatSpecifierWithContext:(void*)context;
93
- (void)setFormatScannerHandler:(id)anObject;
94
- (id)formatScannerHandler;
96
- (unsigned int)flags;
100
- (char)characterSpecifier;
101
- (const char*)currentSpecifier;
103
- (id)setAllowFlags:(BOOL)flag;
104
- (id)setAllowWidth:(BOOL)flag;
105
- (id)setAllowPeriod:(BOOL)flag;
106
- (id)setAllowPrecision:(BOOL)flag;
107
- (id)setAllowModifier:(BOOL)flag;
109
/* A shorthand for sending all -setAllow* messages with !flag as argument */
110
- (id)setAllowOnlySpecifier:(BOOL)flag;
115
- (BOOL)allowPrecision;
116
- (BOOL)allowModifier;
120
#endif /* __FormatScanner_h__ */