2 Copyright (C) 2000-2007 SKYRIX Software AG
3 Copyright (C) 2007 Helge Hess
5 This file is part of SOPE.
7 SOPE is free software; you can redistribute it and/or modify it under
8 the terms of the GNU Lesser General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with SOPE; see the file COPYING. If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #ifndef __NGExtensions_NSString_Formatting_H__
24 #define __NGExtensions_NSString_Formatting_H__
26 #import <Foundation/NSString.h>
30 @interface NSString(XSFormatting)
32 + (id)stringWithCFormat:(const char *)_format arguments:(va_list)_ap;
33 + (id)stringWithCFormat:(const char *)_format, ...;
37 @interface NSMutableString(XSFormatting)
39 - (void)appendFormat:(NSString *)_format arguments:(va_list)_ap;
40 - (void)appendFormat:(NSString *)_format, ...;
44 // C support functions
47 xs_vsnprintf(char *_str, size_t max, const char *fmt, va_list _ap)
49 NSString *obj = [NSString stringWithCFormat:_str arguments:_ap];
50 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1040
51 [obj getCString:_str maxLength:(max - 1)
52 encoding:[NSString defaultCStringEncoding]];
55 [obj getCString:_str maxLength:(max - 1)];
56 return [obj cStringLength]; // return the len the string would have consumed
60 static inline int xs_vsprintf (char *_str, const char *_fmt, va_list _ap) {
61 NSString *obj = [NSString stringWithCFormat:_str arguments:_ap];
62 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1040
63 [obj getCString:_str maxLength:65535 /* no limit ... */
64 encoding:[NSString defaultCStringEncoding]];
67 [obj getCString:_str];
68 return [obj cStringLength]; // return the length of the string
74 // __attribute__ ((format (printf, 2, 3)));
75 // __attribute__ ((format (printf, 3, 4)));
77 int xs_sprintf (char *str, const char *format, ...);
78 int xs_snprintf(char *str, size_t size, const char *format, ...);
80 #endif /* __NGExtensions_NSString_Formatting_H__ */