~ubuntu-branches/ubuntu/edgy/sope/edgy

« back to all changes in this revision

Viewing changes to libFoundation/extensions/FormatScanner.h

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Ley
  • Date: 2005-08-19 16:53:31 UTC
  • Revision ID: james.westby@ubuntu.com-20050819165331-hs683wz1osm708pw
Tags: upstream-4.4rc.2
ImportĀ upstreamĀ versionĀ 4.4rc.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
   FormatScanner.h
 
3
 
 
4
   Copyright (C) 1995, 1996 Ovidiu Predescu and Mircea Oancea.
 
5
   All rights reserved.
 
6
 
 
7
   Author: Ovidiu Predescu <ovidiu@bx.logicnet.ro>
 
8
 
 
9
   This file is part of libFoundation.
 
10
 
 
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
 
15
   documentation.
 
16
 
 
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.
 
23
*/
 
24
 
 
25
#ifndef __FormatScanner_h__
 
26
#define __FormatScanner_h__
 
27
 
 
28
#include <stdarg.h>
 
29
#include <Foundation/NSObject.h>
 
30
 
 
31
@class NSString;
 
32
 
 
33
/*
 
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.
 
46
 *
 
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.
 
50
 */
 
51
 
 
52
typedef enum {
 
53
    FS_ALTERNATE_FORM   = 1,
 
54
    FS_ZERO             = 2,
 
55
    FS_MINUS_SIGN       = 4,
 
56
    FS_PLUS_SIGN        = 8,
 
57
    FS_BLANK            = 16
 
58
} FormatScannerFlags;
 
59
 
 
60
@interface FormatScanner : NSObject
 
61
{
 
62
    int         specifierLen, specifierSize;
 
63
    char        *currentSpecifier;
 
64
    id          handler;
 
65
    unsigned    flags;
 
66
    int         width;
 
67
    int         precision;
 
68
    char        modifier;
 
69
    char        characterSpecifier;
 
70
    BOOL        allowFlags:1;
 
71
    BOOL        allowWidth:1;
 
72
    BOOL        allowPeriod:1;
 
73
    BOOL        allowPrecision:1;
 
74
    BOOL        allowModifier:1;
 
75
}
 
76
 
 
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;
 
80
 
 
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;
 
86
 
 
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.
 
90
*/
 
91
- (BOOL)handleFormatSpecifierWithContext:(void*)context;
 
92
 
 
93
- (void)setFormatScannerHandler:(id)anObject;
 
94
- (id)formatScannerHandler;
 
95
 
 
96
- (unsigned int)flags;
 
97
- (int)width;
 
98
- (int)precision;
 
99
- (char)modifier;
 
100
- (char)characterSpecifier;
 
101
- (const char*)currentSpecifier;
 
102
 
 
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;
 
108
 
 
109
/* A shorthand for sending all -setAllow* messages with !flag as argument */
 
110
- (id)setAllowOnlySpecifier:(BOOL)flag;
 
111
 
 
112
- (BOOL)allowFlags;
 
113
- (BOOL)allowWidth;
 
114
- (BOOL)allowPeriod;
 
115
- (BOOL)allowPrecision;
 
116
- (BOOL)allowModifier;
 
117
 
 
118
@end
 
119
 
 
120
#endif /* __FormatScanner_h__ */
 
121
 
 
122
/*
 
123
  Local Variables:
 
124
  c-basic-offset: 4
 
125
  tab-width: 8
 
126
  End:
 
127
*/