ftp.nice.ch/Attic/openStep/implementation/gnustep/sources/libFoundation.0.7.tgz#/libFoundation-0.7/FoundationExtensions/extensions/FormatScanner.h

This is FormatScanner.h in view mode; [Download] [Up]

/* 
   Copyright (C) 1996 
	Ovidiu Predescu <ovidiu@bx.logicnet.ro>
	Mircea Oancea <mircea@jupiter.elcom.pub.ro>

   Author: Ovidiu Predescu <ovidiu@bx.logicnet.ro>

   This file is part of the FoundationExtensions library.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with this library; see the file COPYING.LIB.
   If not, write to the Free Software Foundation,
   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#ifndef __FormatScanner_h__
#define __FormatScanner_h__

#include <stdarg.h>
#include <Foundation/NSObject.h>

@class NSString;

/*
 * A FormatScanner scans a NSString format. When it reaches a specifier
 * similar to printf(3S), it calls a handler object previously registered to
 * it. The handler object is usually inherited from the DefaultScannerHandler
 * class. The handler object maintains a mapping between format characters and
 * selectors that have to be called when a specifier is found in the format
 * string. The selector must have exactly two arguments: the first one is a
 * pointer to a va_list and the second one is the format scanner. It is the
 * responsability of handler to increase the pointer to the va_list with the
 * size of the object it handles. During the execution of the method the
 * scanner calls, the handler can ask the scanner about the flags, width,
 * precision, modifiers and the specifier character. The method should return a
 * NSString object that represents the converted object.
 *
 * FormatScanner is an abstract class. Use the PrintfFormatScanner class that
 * is used to write printf-like functions. Additional classes can be inherited
 * to write scanf-like functions.
 */

typedef enum {
    FS_ALTERNATE_FORM	= 1,
    FS_ZERO		= 2,
    FS_MINUS_SIGN	= 4,
    FS_PLUS_SIGN	= 8,
    FS_BLANK		= 16
} FormatScannerFlags;

@interface FormatScanner : NSObject
{
    int		specifierLen, specifierSize;
    char*	currentSpecifier;
    id		handler;
    unsigned	flags;
    int		width;
    int		precision;
    char	modifier;
    char	characterSpecifier;
    struct {
	int	allowFlags:1;
	int	allowWidth:1;
	int	allowPeriod:1;
	int	allowPrecision:1;
	int	allowModifier:1;
    } boolFlags;
}

/* This method start the searching of specifiers in `format'. `context' is
   passed in handleFormatSpecifierWithContext: unmodified. */
- (BOOL)parseFormatString:(NSString*)format context:(void*)context;

/* This method is called whenever a string between two specifiers is found.
   Rewrite it in subclasses to perform whatever action you want (for example
   to collect them in a result string if you're doing printf). The method 
   should return NO if the scanning of format should stop. */
- (BOOL)handleOrdinaryString:(NSString*)string;

/* This method is called whenever a format specifier is found in `format'.
   Again, rewrite this method in subclasses to perform whatever action you
   want. The method should return NO if the scanning of the format should stop.
*/
- (BOOL)handleFormatSpecifierWithContext:(void*)context;

- (void)setFormatScannerHandler:(id)anObject;
- (id)formatScannerHandler;

- (unsigned int)flags;
- (int)width;
- (int)precision;
- (char)modifier;
- (char)characterSpecifier;
- (const char*)currentSpecifier;

- setAllowFlags:(BOOL)flag;
- setAllowWidth:(BOOL)flag;
- setAllowPeriod:(BOOL)flag;
- setAllowPrecision:(BOOL)flag;
- setAllowModifier:(BOOL)flag;

/* A shorthand for sending all -setAllow* messages with !flag as argument */
- setAllowOnlySpecifier:(BOOL)flag;

- (BOOL)allowFlags;
- (BOOL)allowWidth;
- (BOOL)allowPeriod;
- (BOOL)allowPrecision;
- (BOOL)allowModifier;

@end

#endif /* __FormatScanner_h__ */

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.