mirror of
https://github.com/touchHLE/touchHLE.git
synced 2026-01-31 01:25:24 +01:00
Implement [NSString stringWithContentsOfFile:]
Change-Id: I0dfa16c5e3ccaa91dcebec8adc759536026b36ba
This commit is contained in:
@@ -288,6 +288,12 @@ pub const CLASSES: ClassExports = objc_classes! {
|
||||
autorelease(env, new)
|
||||
}
|
||||
|
||||
+ (id)stringWithContentsOfFile:(id)path { // NSString*
|
||||
let new: id = msg![env; this alloc];
|
||||
let new: id = msg![env; new initWithContentsOfFile:path];
|
||||
autorelease(env, new)
|
||||
}
|
||||
|
||||
+ (id)stringWithContentsOfFile:(id)path // NSString*
|
||||
encoding:(NSStringEncoding)encoding
|
||||
error:(MutPtr<id>)error { // NSError**
|
||||
@@ -1185,6 +1191,28 @@ pub const CLASSES: ClassExports = objc_classes! {
|
||||
msg![env; this initWithBytes:c_string length:len encoding:encoding]
|
||||
}
|
||||
|
||||
- (id)initWithContentsOfFile:(id)path { // NSString*
|
||||
// TODO: avoid copy?
|
||||
let path = to_rust_string(env, path);
|
||||
let Ok(bytes) = env.fs.read(GuestPath::new(&path)) else {
|
||||
return nil;
|
||||
};
|
||||
|
||||
let encoding = if bytes[..2] == [0xFE, 0xFF] || bytes[..2] == [0xFF, 0xFE] {
|
||||
NSUTF16StringEncoding
|
||||
} else if bytes[..3] == [0xEF, 0xBB, 0xBF] {
|
||||
NSUTF8StringEncoding
|
||||
} else {
|
||||
msg_class![env; NSString defaultCStringEncoding]
|
||||
};
|
||||
|
||||
let host_object = StringHostObject::decode(Cow::Owned(bytes), encoding);
|
||||
|
||||
*env.objc.borrow_mut(this) = host_object;
|
||||
|
||||
this
|
||||
}
|
||||
|
||||
- (id)initWithContentsOfFile:(id)path // NSString*
|
||||
encoding:(NSStringEncoding)encoding
|
||||
error:(MutPtr<id>)error { // NSError**
|
||||
|
||||
Reference in New Issue
Block a user