Permalink
Browse files

Merge pull request #12 from AdamBuckley/master

Allow user to set encoding within CTidy
  • Loading branch information...
2 parents b9fe0fc + 1c59eca commit b19c60f09bca8fa309668b299af45979ce7493d8 @schwa schwa committed Nov 2, 2011
Showing with 12 additions and 6 deletions.
  1. +2 −2 Source/Tidy/CTidy.h
  2. +10 −4 Source/Tidy/CTidy.m
View
@@ -47,8 +47,8 @@ typedef enum {
+ (CTidy *)tidy;
-- (NSData *)tidyData:(NSData *)inData inputFormat:(CTidyFormat)inInputFormat outputFormat:(CTidyFormat)inOutputFormat diagnostics:(NSString **)outDiagnostics error:(NSError **)outError;
-- (NSString *)tidyString:(NSString *)inString inputFormat:(CTidyFormat)inInputFormat outputFormat:(CTidyFormat)inOutputFormat diagnostics:(NSString **)outDiagnostics error:(NSError **)outError;
+- (NSData *)tidyData:(NSData *)inData inputFormat:(CTidyFormat)inInputFormat outputFormat:(CTidyFormat)inOutputFormat encoding:(const char *)encoding diagnostics:(NSString **)outDiagnostics error:(NSError **)outError;
+- (NSString *)tidyString:(NSString *)inString inputFormat:(CTidyFormat)inInputFormat outputFormat:(CTidyFormat)inOutputFormat encoding:(const char *)encoding diagnostics:(NSString **)outDiagnostics error:(NSError **)outError;
@end
View
@@ -45,7 +45,7 @@ + (CTidy *)tidy
return([[[self alloc] init] autorelease]);
}
-- (NSData *)tidyData:(NSData *)inData inputFormat:(CTidyFormat)inInputFormat outputFormat:(CTidyFormat)inOutputFormat diagnostics:(NSString **)outDiagnostics error:(NSError **)outError
+- (NSData *)tidyData:(NSData *)inData inputFormat:(CTidyFormat)inInputFormat outputFormat:(CTidyFormat)inOutputFormat encoding:(const char*)encoding diagnostics:(NSString **)outDiagnostics error:(NSError **)outError
{
TidyDoc theTidyDocument = tidyCreate();
@@ -71,7 +71,10 @@ - (NSData *)tidyData:(NSData *)inData inputFormat:(CTidyFormat)inInputFormat out
theResultCode = tidyOptSetBool(theTidyDocument, TidyForceOutput, YES);
NSAssert(theResultCode >= 0, @"tidyOptSetBool() should return 0");
-theResultCode = tidySetOutCharEncoding(theTidyDocument, "utf8");
+// Set encoding - same for input and output
+theResultCode = tidySetInCharEncoding(theTidyDocument, encoding)
+NSAssert(theResultCode >= 0, @"tidySetInCharEncoding() should return 0");
+theResultCode = tidySetOutCharEncoding(theTidyDocument, encoding);
NSAssert(theResultCode >= 0, @"tidySetOutCharEncoding() should return 0");
// Create an error buffer
@@ -139,7 +142,7 @@ - (NSData *)tidyData:(NSData *)inData inputFormat:(CTidyFormat)inInputFormat out
return(theOutput);
}
-- (NSString *)tidyString:(NSString *)inString inputFormat:(CTidyFormat)inInputFormat outputFormat:(CTidyFormat)inOutputFormat diagnostics:(NSString **)outDiagnostics error:(NSError **)outError
+- (NSString *)tidyString:(NSString *)inString inputFormat:(CTidyFormat)inInputFormat outputFormat:(CTidyFormat)inOutputFormat encoding:(const char*)encoding diagnostics:(NSString **)outDiagnostics error:(NSError **)outError
{
TidyDoc theTidyDocument = tidyCreate();
@@ -165,7 +168,10 @@ - (NSString *)tidyString:(NSString *)inString inputFormat:(CTidyFormat)inInputFo
theResultCode = tidyOptSetBool(theTidyDocument, TidyForceOutput, YES);
NSAssert(theResultCode >= 0, @"tidyOptSetBool() should return 0");
-theResultCode = tidySetCharEncoding(theTidyDocument, "utf8");
+// Set encoding - same for input and output
+theResultCode = tidySetInCharEncoding(theTidyDocument, encoding)
+NSAssert(theResultCode >= 0, @"tidySetInCharEncoding() should return 0");
+theResultCode = tidySetOutCharEncoding(theTidyDocument, encoding);
NSAssert(theResultCode >= 0, @"tidySetOutCharEncoding() should return 0");
// Create an error buffer

0 comments on commit b19c60f

Please sign in to comment.