Author: rfm
Date: Mon Mar 6 10:43:15 2017
New Revision: 40366
URL: http://svn.gna.org/viewcvs/gnustep?rev=40366&view=rev
Log:
Whitespace parsing improvements and tweak to -setDebug: method
Modified:
libs/webservices/trunk/ChangeLog
libs/webservices/trunk/GWSCoder.h
libs/webservices/trunk/GWSCoder.m
libs/webservices/trunk/GWSElement.h
libs/webservices/trunk/GWSElement.m
libs/webservices/trunk/tests/test
Modified: libs/webservices/trunk/ChangeLog
URL:
http://svn.gna.org/viewcvs/gnustep/libs/webservices/trunk/ChangeLog?rev=40366&r1=40365&r2=40366&view=diff
==============================================================================
--- libs/webservices/trunk/ChangeLog (original)
+++ libs/webservices/trunk/ChangeLog Mon Mar 6 10:43:15 2017
@@ -1,3 +1,16 @@
+2017-03-06 Richard Frith-Macdonald <[email protected]>
+
+ * GSWCoder.h:
+ * GSWCoder.m:
+ Change signature of -setDebug: method to be consistent with other
+ classes using a method of the same name.
+ Add option to preserve white space when parsing XML.
+ * GSWElement.h:
+ * GSWElement.m:
+ Don't strip white space when accumulating string data, but provide
+ a -condense: method to do it at the end. Allows more control over
+ whitespace handling.
+
2016-10-25 Richard Frith-Macdonald <[email protected]>
* GWSService.h:
Modified: libs/webservices/trunk/GWSCoder.h
URL:
http://svn.gna.org/viewcvs/gnustep/libs/webservices/trunk/GWSCoder.h?rev=40366&r1=40365&r2=40366&view=diff
==============================================================================
--- libs/webservices/trunk/GWSCoder.h (original)
+++ libs/webservices/trunk/GWSCoder.h Mon Mar 6 10:43:15 2017
@@ -86,11 +86,12 @@
BOOL _fault; // YES while building a fault.
BOOL _oldparser; // YES if no namespace support.
BOOL _crlf; // YES to use CRLF rather than LF
+ BOOL _preferSloppyParser; // Whether the tolerant GNUstep
+ // parser should be used.
+ BOOL _preserveSpace; // YES to preserve white spece
unsigned _level; // Current indentation level.
NSMutableString *_ms; // Not retained.
id _delegate; // Not retained.
- BOOL _preferSloppyParser; // Whether the old GNUstep
- // parser should be preferred
}
/** Creates and returns an autoreleased instance.<br />
@@ -180,6 +181,17 @@
- (id) parseXSI: (NSString*)type string: (NSString*)value;
/**
+ * Whether the more tolerant, non-libxml2 parser in GNUstep should be used.
+ */
+- (BOOL) preferSloppyParser;
+
+/**
+ * Whether whitespace in contrent adjacent to element markup should be
+ * stripped/ignored.
+ */
+- (BOOL) preserveSpace;
+
+/**
* Resets parsing and/or building, releasing any temporary
* data stored during parse etc.<br />
* This does not alter the effects of the -setCompact:
@@ -195,34 +207,38 @@
*/
- (void) setCompact: (BOOL)flag;
-/** Specifies whether newlines are represented as a single LF or as a
- * CRLF sequence when generating output.<br />
+/** Specifies whether newlines between elements are represented as a
+ * single LF or as a CRLF sequence when generating output.<br />
* NB this has no effect for compact output (where all output is on a
* single line).
*/
- (void) setCRLF: (BOOL)flag;
/** Specifies whether debug information is enabled. See -debug for more
- * information.
- */
-- (void) setDebug: (BOOL)flag;
+ * information.<br />
+ * A non-zero setting sets debg to YES while a zero setting sets it to NO.
+ * The method returns the previous setting.
+ */
+- (int) setDebug: (int)flag;
+
+/**
+ * Specifies whether the more tolerant, non-libxml2 parser should be used if
+ * available. This supports a wider range of not-entirely valid XML, but
+ * omits features such as external entity support.
+ */
+- (void) setPreferSloppyParser: (BOOL)flag;
+
+/** Specifies whether leading and trailing whie space character content
+ * of an element is preserved or stripped/ignored (standard xml behavior
+ * is to strip/ignore it).
+ */
+- (void) setPreserveSpace: (BOOL)flag;
/** Decrease the indentation level used while creating an XML document.
* creating an XML document.
*/
- (void) unindent;
-/**
- * Whether the old non-libxml2 parser in GNUstep should be preferred.
- */
-- (BOOL)preferSloppyParser;
-
-/**
- * Specifies whether the old non-libxml2 parser should be preferred if
- * available. This supports a wider range of not-entirely valid XML, but
- * omits features such as external entity support.
- */
-- (void)setPreferSloppyParser: (BOOL)flag;
@end
/** The methods in this category are used to handle web services
Modified: libs/webservices/trunk/GWSCoder.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/webservices/trunk/GWSCoder.m?rev=40366&r1=40365&r2=40366&view=diff
==============================================================================
--- libs/webservices/trunk/GWSCoder.m (original)
+++ libs/webservices/trunk/GWSCoder.m Mon Mar 6 10:43:15 2017
@@ -161,16 +161,6 @@
- (BOOL) compact
{
return _compact;
-}
-
-- (BOOL) preferSloppyParser
-{
- return _preferSloppyParser;
-}
-
-- (void) setPreferSloppyParser: (BOOL)flag
-{
- _preferSloppyParser = flag;
}
- (void) dealloc
@@ -1125,12 +1115,26 @@
format: @"Element missmatch found '%@' expecting '%@'",
elementName, [top name]];
}
+ if (NO == _preserveSpace)
+ {
+ [top condense: NO];
+ }
count = [_stack count];
if (count > 1)
{
[(GWSElement*)[_stack objectAtIndex: count - 2] addChild: top];
[_stack removeLastObject];
}
+}
+
+- (BOOL) preferSloppyParser
+{
+ return _preferSloppyParser;
+}
+
+- (BOOL) preserveSpace
+{
+ return _preserveSpace;
}
- (void) reset
@@ -1151,15 +1155,34 @@
_crlf = flag;
}
-- (void) setDebug: (BOOL)flag
-{
- _debug = flag;
+/* Much software uses integer settings for debug levels, so to selector
+ * type conflicts we use the same convention even though we are using it
+ * as a boolean.
+ */
+- (int) setDebug: (int)flag
+{
+ BOOL old = _debug;
+
+ _debug = flag ? YES : NO;
+ return old;
+}
+
+- (void) setPreferSloppyParser: (BOOL)flag
+{
+ _preferSloppyParser = flag;
+}
+
+- (void) setPreserveSpace: (BOOL)flag
+{
+ _preserveSpace = flag;
}
- (void) unindent
{
if (_level > 0)
- _level--;
+ {
+ _level--;
+ }
}
@end
Modified: libs/webservices/trunk/GWSElement.h
URL:
http://svn.gna.org/viewcvs/gnustep/libs/webservices/trunk/GWSElement.h?rev=40366&r1=40365&r2=40366&view=diff
==============================================================================
--- libs/webservices/trunk/GWSElement.h (original)
+++ libs/webservices/trunk/GWSElement.h Mon Mar 6 10:43:15 2017
@@ -96,8 +96,7 @@
content: (NSString*)content, ...;
/** Adds a string to the content of the receiver. New content is appended
- * to any existing content (with any white space between the two parts
- * being condensed to a single space).
+ * to any existing content.
*/
- (void) addContent: (NSString*)content;
@@ -121,9 +120,15 @@
*/
- (NSArray*) children;
+/** Condenses the character content of the receiver by stripping leading
+ * and trailing white space. If the internal flag is YES, any sequence of
+ * internal white space is also condensed to a single character by deleting
+ * all but the first character.
+ */
+- (void) condense: (BOOL)internal;
+
/** Returns the content text of the receiver. This may be an empty string
- * if no content has been added to the receiver (but will never be nil).<br />
- * The returned value will have no leading or trailing white space.
+ * if no content has been added to the receiver (but will never be nil).
*/
- (NSString*) content;
@@ -330,7 +335,7 @@
- (void) setAttribute: (NSString*)attribute forKey: (NSString*)key;
/** Sets the value of the content string of the receiver, replacing any
- * content already present. Any leading white space is removed.<br />
+ * content already present.<br />
* You may use an empty string or nil to remove content from the
* receiver.
*/
Modified: libs/webservices/trunk/GWSElement.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/webservices/trunk/GWSElement.m?rev=40366&r1=40365&r2=40366&view=diff
==============================================================================
--- libs/webservices/trunk/GWSElement.m (original)
+++ libs/webservices/trunk/GWSElement.m Mon Mar 6 10:43:15 2017
@@ -44,7 +44,7 @@
}
}
-#define MEMBER(X) (*cimImp)(ws, cimSel, (X))
+#define ISSPACE(X) (*cimImp)(ws, cimSel, (X))
- (void) addContent: (NSString*)content
{
@@ -54,18 +54,6 @@
{
if (_content == nil)
{
- NSUInteger pos = 0;
-
- /* Ignore leading white space within an element.
- */
- while (pos < length && MEMBER([content characterAtIndex: pos]))
- {
- pos++;
- }
- if (pos > 0)
- {
- content = [content substringFromIndex: pos];
- }
_content = [content mutableCopyWithZone: 0];
}
else
@@ -241,6 +229,83 @@
}
}
+- (void) condense: (BOOL)internal
+{
+ NSUInteger length = [_content length];
+ NSUInteger end = length;
+ NSUInteger start = 0;
+
+ if (length > 0)
+ {
+ SEL caiSel = @selector(characterAtIndex:);
+ unichar (*caiImp)(NSString*, SEL, NSUInteger);
+ unichar letter;
+
+ caiImp = (unichar (*)())[_content methodForSelector: caiSel];
+
+ while (end > 0)
+ {
+ letter = (*caiImp)(_content, caiSel, end-1);
+ if (ISSPACE(letter) == NO)
+ {
+ break;
+ }
+ end--;
+ }
+ while (start < end)
+ {
+ letter = (*caiImp)(_content, caiSel, start);
+ if (ISSPACE(letter) == NO)
+ {
+ break;
+ }
+ start++;
+ }
+ if (end != length)
+ {
+ /* Trim trailing space.
+ */
+ [_content deleteCharactersInRange: NSMakeRange(end, length - end)];
+ }
+ if (start > 0)
+ {
+ /* Trim leading space.
+ */
+ [_content deleteCharactersInRange: NSMakeRange(0, start)];
+ }
+ length = end - start;
+ if (YES == internal && (end = length) > 0)
+ {
+ /* Condense internal sequences of spaces.
+ */
+ while (end-- > 0)
+ {
+ letter = (*caiImp)(_content, caiSel, end);
+ if (ISSPACE(letter) == YES)
+ {
+ start = end;
+ while (start-- > 0)
+ {
+ letter = (*caiImp)(_content, caiSel, start);
+ if (ISSPACE(letter) == NO)
+ {
+ if (end - start > 1)
+ {
+ /* Reduce multiple whitespace characters to
+ * a single space by deleting all but first.
+ */
+ [_content deleteCharactersInRange:
+ NSMakeRange(start + 1, end - start - 1)];
+ }
+ }
+ }
+ end = start;
+ }
+ }
+ }
+ }
+}
+
- (NSString*) content
{
if (_content == nil)
@@ -249,16 +314,7 @@
}
else
{
- NSUInteger pos = [_content length];
-
- /* Strip trailing white space (leading space was already stripped as
- * content was added).
- */
- while (pos > 0 && MEMBER([_content characterAtIndex: pos-1]))
- {
- pos--;
- }
- return [_content substringToIndex: pos];
+ return [[_content copyWithZone: 0] autorelease];
}
}
Modified: libs/webservices/trunk/tests/test
URL:
http://svn.gna.org/viewcvs/gnustep/libs/webservices/trunk/tests/test?rev=40366&r1=40365&r2=40366&view=diff
==============================================================================
--- libs/webservices/trunk/tests/test (original)
+++ libs/webservices/trunk/tests/test Mon Mar 6 10:43:15 2017
@@ -8,35 +8,37 @@
echo "Error count on completion should be zero"
echo ""
+DIR=../obj/`gnustep-config --host-ldir`
+
err=0
-../obj/testGWSSOAPCoder -Internal YES
+$DIR/testGWSSOAPCoder -Internal YES
if [ $? = 1 ]; then
err=`expr $err + 1`
fi
-../obj/testGWSSOAPCoder -Decode xml1 -Compare pl1
+$DIR/testGWSSOAPCoder -Decode xml1 -Compare pl1
if [ $? = 1 ]; then
err=`expr $err + 1`
fi
-../obj/testGWSSOAPCoder -Decode xml2 -Compare pl2
+$DIR/testGWSSOAPCoder -Decode xml2 -Compare pl2
if [ $? = 1 ]; then
err=`expr $err + 1`
fi
-../obj/testGWSSOAPCoder -Decode xml3 -Compare pl3
+$DIR/testGWSSOAPCoder -Decode xml3 -Compare pl3
if [ $? = 1 ]; then
err=`expr $err + 1`
fi
-../obj/testGWSSOAPCoder -Encode pl4 -Compare xml4 \
+$DIR/testGWSSOAPCoder -Encode pl4 -Compare xml4 \
-WSDL test4.wsdl -Service ViewDevice -Method getDevice
if [ $? = 1 ]; then
err=`expr $err + 1`
fi
-../obj/testGWSJSONCoder -Decode json1 -Compare jpl1
+$DIR/testGWSJSONCoder -Decode json1 -Compare jpl1
if [ $? = 1 ]; then
err=`expr $err + 1`
fi
_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs