aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPDataAdditions.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-09-24 12:51:08 +0000
committerBibiko <bibiko@eva.mpg.de>2009-09-24 12:51:08 +0000
commita2a8d1b068db4ff8e102ce6931191064a2246fad (patch)
tree3e9ea8861d7dc7f8aa332bf3f5a288cc8f518f53 /Source/SPDataAdditions.m
parente19f96073ffeaa6b0ae60f67206695e271ce70cc (diff)
downloadsequelpro-a2a8d1b068db4ff8e102ce6931191064a2246fad.tar.gz
sequelpro-a2a8d1b068db4ff8e102ce6931191064a2246fad.tar.bz2
sequelpro-a2a8d1b068db4ff8e102ce6931191064a2246fad.zip
• eliminated the deprecated method 'stringWithCString' and simplified the method 'dataToFormattedHexString' a bit (this fixes the issue for broken lines as well - seen under OSX 10.6)
Diffstat (limited to 'Source/SPDataAdditions.m')
-rw-r--r--Source/SPDataAdditions.m73
1 files changed, 27 insertions, 46 deletions
diff --git a/Source/SPDataAdditions.m b/Source/SPDataAdditions.m
index 1af06f5b..7069866c 100644
--- a/Source/SPDataAdditions.m
+++ b/Source/SPDataAdditions.m
@@ -267,23 +267,22 @@ static char base64encodingTable[64] = {
returns the hex representation of the given data
*/
{
- unsigned i;
- unsigned totalLength = [self length];
- int bytesPerLine = 16;
+ NSUInteger i, j;
+ NSUInteger totalLength = [self length];
+ NSUInteger bytesPerLine = 16;
NSMutableString *retVal = [NSMutableString string];
- char *nodisplay = "\t\n\r\f";
-
+
// get the length of the longest location
- int longest = [(NSString *)[NSString stringWithFormat:@"%X", totalLength - ( totalLength % bytesPerLine )] length];
-
+ NSUInteger longest = [(NSString *)[NSString stringWithFormat:@"%X", totalLength - ( totalLength % bytesPerLine )] length];
+
for ( i = 0; i < totalLength; i += bytesPerLine ) {
- int j;
+
NSMutableString *hex = [[NSMutableString alloc] initWithCapacity:(3 * bytesPerLine - 1)];
NSMutableString *location = [[NSMutableString alloc] initWithCapacity:(longest + 2)];
- NSMutableString *chars = [[NSMutableString alloc] init];
+
unsigned char *buffer;
- int buffLength = bytesPerLine;
-
+ NSUInteger buffLength = bytesPerLine;
+
// add hex value of location
[location appendString:[NSString stringWithFormat:@"%X", i]];
@@ -296,56 +295,38 @@ static char base64encodingTable[64] = {
if ( i + buffLength >= totalLength ) {
buffLength = totalLength - i;
}
- buffer = (unsigned char*) malloc( sizeof( unsigned char ) * buffLength );
- NSRange range = { i, buffLength };
- [self getBytes:buffer range:range];
+
+ buffer = (unsigned char*) malloc( sizeof( unsigned char ) * buffLength + 1);
+
+ [self getBytes:buffer range:NSMakeRange(i, buffLength)];
// build the hex string
for ( j = 0; j < buffLength; j++ ) {
- unsigned char byte = *(buffer + j);
- if ( byte < 16 ) {
- [hex appendString:@"0"];
- }
- [hex appendString:[NSString stringWithFormat:@"%X", byte]];
- [hex appendString:@" "];
-
- // if the char is undisplayable, replace it with "."
- unsigned char current;
- int count = 0;
- while ( ( current = *(nodisplay + count++) ) > 0 ) {
- if ( current == byte ) {
- *(buffer + j) = '.';
- break;
- }
- }
+
+ [hex appendString:[NSString stringWithFormat:@"%02X ", *(buffer + j)]];
+
+ // Replace non-displayed bytes by '.'
+ // non-displayed bytes are all bytes whose hex code is less than 0x20
+ if(*(buffer + j) < ' ') *(buffer + j) = '.';
+
}
-
+ // Create a NULL-terminated buffer for [NSString stringWithFormat:@"%s"]
+ *(buffer + j) = '\0';
+
// add padding to missing hex values.
for ( j = 0; j < bytesPerLine - buffLength; j++ ) {
[hex appendString:@" "];
}
-
- // remove extra ghost characters
- [chars appendString:[NSString stringWithCString:(char *)buffer]];
- if ( [chars length] > bytesPerLine ) {
- [chars deleteCharactersInRange:NSMakeRange( bytesPerLine, [chars length] - bytesPerLine )];
- }
-
+
// build line
- [retVal appendString:location];
- [retVal appendString:@" "];
- [retVal appendString:hex];
- [retVal appendString:@" "];
- [retVal appendString:chars];
- [retVal appendString:@"\n"];
+ [retVal appendFormat:@"%@ %@ %@\n", location, hex, [NSString stringWithFormat:@"%s", buffer]];
// clean up
[hex release];
- [chars release];
[location release];
free( buffer );
}
-
+
return retVal;
}