- Timestamp:
- Apr 21, 2009 8:20:32 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lang/tcl/tests/encode.test
r1414 r1415 309 309 } {0 -hi} 310 310 311 test encode-4.0 {is binary (isxml) test with invalid XML characters} { 312 list [catch {Rappture::encoding::is binary "formfeed \f"} msg] $msg 313 } {0 yes} 314 test encode-4.1 {is binary (isxml) test with invalid XML characters} { 315 list [catch {Rappture::encoding::is binary "backspace \b"} msg] $msg 316 } {0 yes} 317 test encode-4.2 {is binary (isxml) test with invalid XML characters} { 318 list [catch {Rappture::encoding::is binary "vertical tab \v"} msg] $msg 319 } {0 yes} 320 test encode-4.3 {is binary (isxml) test with invalid XML characters} { 321 list [catch {Rappture::encoding::is binary "high-order bit \x80"} msg] $msg 322 } {0 yes} 323 test encode-4.4 {is binary (isxml) test with invalid XML characters} { 324 list [catch {Rappture::encoding::is binary "high-order bit \xFF"} msg] $msg 325 } {0 yes} 326 test encode-4.5 {is binary (isxml) test with invalid XML characters} { 327 list [catch {Rappture::encoding::is binary "NUL \0"} msg] $msg 328 } {0 yes} 329 test encode-4.6 {is binary (isxml) test with invalid XML characters} { 330 list [catch {Rappture::encoding::is binary "BEL \a"} msg] $msg 331 } {0 yes} 332 test encode-4.7 {is binary (isxml) test with valid XML characters} { 333 list [catch {Rappture::encoding::is binary "tab/cr/nl \t\r\n "} msg] $msg 334 } {0 no} 335 test encode-4.8 {is binary (isxml) test with valid XML characters} { 336 list [catch { 337 set string "\t\r\n" 338 for { set i 0x20 } { $i <= 0x7F } { incr i } { 339 append string [format %c $i] 340 } 341 Rappture::encoding::is binary $string 342 } msg] $msg 343 } {0 no} 344 345 test encode-4.8 {is binary (isxml) test with all characters} { 346 list [catch { 347 set result {} 348 for { set i 0 } { $i <= 0xFF } { incr i } { 349 set string [format %c $i] 350 if { ![Rappture::encoding::is binary $string] } { 351 lappend result $i 352 } 353 } 354 set result 355 } msg] $msg 356 } {0 {9 10 13 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127}} 357 311 358 312 359 ::tcltest::cleanupTests -
trunk/src/core/RpEncode.cc
r1414 r1415 16 16 #include <cstring> 17 17 18 18 19 /**********************************************************************/ 19 20 // FUNCTION: Rappture::encoding::isbinary() 20 21 /// isbinary checks to see if given string is binary. 22 21 23 /** 22 24 * Checks to see if any of size characters in *buf are binary … … 26 28 */ 27 29 30 /* 31 * Valid XML (ASCII encoded) characters 0-127: 32 * 33 * 0x9 (\t) 0xA (\n) 0xD (\r) and 34 * 0x20 (space) through 0x7F (del) 35 * 36 * This isn't for UTF-8, only ASCII. We don't allow high-order bit 37 * characters for ASCII editors. 38 */ 39 static unsigned char _xmlchars[256] = { 40 /* - 0 1 2 3 4 5 6 7 8 9 A B C D E F */ 41 /*00*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 42 /*10*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 43 /*20*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 44 /*30*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 45 /*40*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 46 /*50*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 47 /*60*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 48 /*70*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 49 /*80*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 50 /*90*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 51 /*A0*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 52 /*B0*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 53 /*C0*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 54 /*E0*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55 /*F0*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 56 }; 57 58 /* 59 * This routine is misnamed "isBinary". By definition, all strings are binary, 60 * even the ones with just letters or digits. It's really a test if the 61 * string can be used by XML verbatim and if it can be read by the usual ASCII 62 * editors (the reason high-order bit characters are disallowed). [Note we 63 * aren't checking if entity replacements are necessary.] 64 * 65 * The "is*" routines should be moved somewhere else since they really don't 66 * have anything to do with encoding/decoding. 67 */ 28 68 bool 29 69 Rappture::encoding::isBinary(const char* buf, int size) 30 70 { 31 71 if (buf == NULL) { 32 return 0;72 return false; /* Really should let this segfault. */ 33 73 } 34 74 if (size < 0) { 35 75 size = strlen(buf); 36 76 } 37 const char *cp, *endPtr; 38 for (cp = buf, endPtr = buf + size; cp < endPtr; cp++) { 39 if (((*cp >= '\000') && (*cp <= '\010')) || 40 ((*cp >= '\013') && (*cp <= '\014')) || 41 ((*cp >= '\016') && (*cp <= '\037')) || 42 ((*cp >= '\177') && (*cp <= '\377')) ) { 43 // data is binary 44 return true; 45 } 77 const unsigned char *cp, *endPtr; 78 for (cp = (const unsigned char *)buf, endPtr = cp + size; cp < endPtr; 79 cp++) { 80 if (!_xmlchars[*cp]) { 81 return true; 82 } 46 83 } 47 84 return false; … … 52 89 { 53 90 if (buf == NULL) { 54 return 0;91 return false; /* Really should let this segfault. */ 55 92 } 56 93 if (size < 0) {
Note: See TracChangeset
for help on using the changeset viewer.