forked from mykeepass/KeePassLib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.m
64 lines (52 loc) · 1.53 KB
/
Utils.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
//
// Utils.m
// KeePass2
//
// Created by Qiang Yu on 1/7/10.
// Copyright 2010 Qiang Yu. All rights reserved.
//
#import "Utils.h"
@implementation Utils
+(ByteBuffer *) createByteBufferForString:(NSString *)string coding:(NSStringEncoding)encoding{
NSUInteger size = [string lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
ByteBuffer * result = [[ByteBuffer alloc] initWithSize:size];
NSRange range;
range.location = 0; range.length=[string length];
[string getBytes:result._bytes maxLength:size usedLength:nil encoding:NSUTF8StringEncoding
options:0 range:range remainingRange:nil];
return result;
}
+(uint8_t)readInt8LE:(id<InputDataSource>) ds{
uint8_t value;
[ds readBytes:(uint8_t *)(&value) length:1];
return (value);
}
+(uint16_t)readInt16LE:(id<InputDataSource>) ds{
uint16_t value;
[ds readBytes:(uint8_t *)(&value) length:2];
return CFSwapInt16LittleToHost(value);
}
+(uint32_t)readInt32LE:(id<InputDataSource>) ds{
uint32_t value;
[ds readBytes:(uint8_t *)(&value) length:4];
return CFSwapInt32LittleToHost(value);
}
+(uint64_t)readInt64LE:(id<InputDataSource>)ds{
uint64_t value;
[ds readBytes:(uint8_t *)(&value) length:8];
return CFSwapInt64LittleToHost(value);
}
+(BOOL)emptyString:(NSString *)str{
return (!str || ![str length]);
}
NSInteger EntrySort(id num1, id num2, void *context){
int v1 = [num1 intValue];
int v2 = [num2 intValue];
if (v1 < v2)
return NSOrderedAscending;
else if (v1 > v2)
return NSOrderedDescending;
else
return NSOrderedSame;
}
@end