- Timestamp:
- May 10, 2007 8:00:44 PM (17 years ago)
- Location:
- trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/RpEncode.cc
r675 r725 33 33 isbinary(const char* buf, int size) 34 34 { 35 int index = 0; 36 37 if (size == -1) { 35 if (size < 0) { 38 36 size = strlen(buf); 39 37 } 40 38 41 for (index = 0; index < size; index++) { 42 if (((buf[index] >= '\000') && (buf[index] <= '\010')) || 43 ((buf[index] >= '\013') && (buf[index] <= '\014')) || 44 ((buf[index] >= '\016') && (buf[index] <= '\037')) || 45 ((buf[index] >= '\177') && (buf[index] <= '\377')) ) { 39 for (int index = 0; index < size; index++) { 40 int c = *buf++; 41 if (((c >= '\000') && (c <= '\010')) || 42 ((c >= '\013') && (c <= '\014')) || 43 ((c >= '\016') && (c <= '\037')) || 44 ((c >= '\177') && (c <= '\377')) ) { 46 45 // data is binary 47 46 return index+1; 48 47 } 49 50 48 } 51 49 return 0; -
trunk/src/tcl/src/RpEncodeTclInterface.cc
r684 r725 78 78 79 79 int 80 RpTclEncodingIs ( ClientData cdata, 81 Tcl_Interp *interp, 82 int objc, 83 Tcl_Obj *const objv[] ) 80 RpTclEncodingIs (ClientData cdata, Tcl_Interp *interp, 81 int objc, Tcl_Obj *const objv[]) 84 82 { 85 const char* type = NULL; // type of data being checked86 const char* buf = NULL; // buffer to be checked87 const char* cmdName = NULL;88 89 int typeLen = 0;90 int bufLen = 0; // length of user provided buffer91 int nextarg = 0; // next argument92 93 83 Tcl_ResetResult(interp); 94 95 cmdName = Tcl_GetString(objv[nextarg++]);96 84 97 85 // parse through command line options … … 99 87 Tcl_AppendResult(interp, 100 88 "wrong # args: should be \"", 101 cmdName," binary <string>\"",89 Tcl_GetString(objv[0])," binary <string>\"", 102 90 (char*)NULL); 103 91 return TCL_ERROR; 104 92 } 105 93 106 type = Tcl_GetStringFromObj(objv[nextarg++],&typeLen); 107 buf = Tcl_GetStringFromObj(objv[nextarg++],&bufLen); 108 109 if (strncmp(type,"binary",typeLen) == 0) { 94 const char *type = Tcl_GetString(objv[1]); 95 96 int bufLen; 97 const char *buf = (const char*) Tcl_GetByteArrayFromObj(objv[2],&bufLen); 98 99 if (strcmp(type,"binary") == 0) { 110 100 if (Rappture::encoding::isbinary(buf,bufLen) != 0) { 111 101 // non-ascii character found, return yes 112 Tcl_AppendResult(interp, "yes",(char*)NULL); 113 return TCL_OK; 102 Tcl_AppendResult(interp, "yes", (char*)NULL); 103 } else { 104 Tcl_AppendResult(interp, "no",(char*)NULL); 114 105 } 115 } 116 else { 117 Tcl_AppendResult(interp, "bad option \"", type, 118 "\": should be binary", 119 (char*)NULL); 120 return TCL_ERROR; 121 122 } 123 124 // default return 125 // no binary characters found, return no 126 Tcl_AppendResult(interp, "no",(char*)NULL); 127 return TCL_OK; 106 return TCL_OK; 107 } 108 Tcl_AppendResult(interp, "bad option \"", type, 109 "\": should be binary", 110 (char*)NULL); 111 return TCL_ERROR; 128 112 } 129 113 -
trunk/src/tcl/tests/encode.test
r684 r725 52 52 list [catch {Rappture::encoding::is binary binary "hi"} msg] $msg 53 53 } {1 {wrong # args: should be "Rappture::encoding::is binary <string>"}} 54 55 test is-1.2.2 {Rappture::encoding::is, with an embedded null} { 56 list [catch {Rappture::encoding::is binary "x\000x"} msg] $msg 57 } {0 yes} 54 58 55 59 #----------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.