Skip to content

Commit 4102211

Browse files
committed
Adding a [CCFile loadString] method. It seems useful, and is used many times internally.
1 parent 73e9d16 commit 4102211

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

cocos2d/Support/CCFile.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,17 @@
9292
*/
9393
-(NSData *)loadData:(NSError **)error;
9494

95+
/**
96+
Load the file's contents as a UTF8 string.
97+
98+
@param error If an error occurs, upon return contains an NSError object that describes the problem.
99+
100+
@return The file's complete contents as a UTF8 string.
101+
102+
@since 4.0
103+
*/
104+
-(NSString *)loadString:(NSError **)error;
105+
95106
/**
96107
Opens an input stream to the file so it can be read sequentially.
97108

cocos2d/Support/CCFile.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,11 @@ -(NSData *)loadData:(NSError *__autoreleasing *)error
507507
}
508508
}
509509

510+
-(NSString *)loadString:(NSError **)error;
511+
{
512+
return [[NSString alloc] initWithData:[self loadData:error] encoding:NSUTF8StringEncoding];
513+
}
514+
510515
-(CGImageSourceRef)createCGImageSource
511516
{
512517
if(_loadDataFromStream){

0 commit comments

Comments
 (0)