Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Allow user to set encoding within CTidy #12

Merged
merged 3 commits into from

3 participants

@AdamBuckley

I thought about bring to automate the encoding but realised it might make things cumbersome when the user might want to write their own implementation

@schwa
Owner

Thanks for this.

@schwa schwa merged commit b19c60f into TouchCode:master
@mrloop

CXMLDocument has not been updated to use new CTidy API

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 15, 2011
  1. @AdamBuckley

    Update Source/Tidy/CTidy.h

    AdamBuckley authored
  2. @AdamBuckley

    Update Source/Tidy/CTidy.m

    AdamBuckley authored
  3. @AdamBuckley

    Update Source/Tidy/CTidy.m

    AdamBuckley authored
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 6 deletions.
  1. +2 −2 Source/Tidy/CTidy.h
  2. +10 −4 Source/Tidy/CTidy.m
View
4 Source/Tidy/CTidy.h
@@ -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
14 Source/Tidy/CTidy.m
@@ -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
Something went wrong with that request. Please try again.