forked from appsquickly/typhoon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request appsquickly#442 from appsquickly/type-converters-fix
Removed the singletone TyphoonTypeConverterRegistry
- Loading branch information
Showing
27 changed files
with
536 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
Source/TypeConversion/Helpers/TyphoonColorConversionUtils.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// TYPHOON FRAMEWORK | ||
// Copyright 2015, Typhoon Framework Contributors | ||
// All Rights Reserved. | ||
// | ||
// NOTICE: The authors permit you to use, modify, and distribute this file | ||
// in accordance with the terms of the license agreement accompanying it. | ||
// | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
struct RGBA | ||
{ | ||
CGFloat red; | ||
CGFloat green; | ||
CGFloat blue; | ||
CGFloat alpha; | ||
} rgba; | ||
|
||
@interface TyphoonColorConversionUtils : NSObject | ||
|
||
+ (struct RGBA)colorFromHexString:(NSString *)hexString; | ||
+ (struct RGBA)colorFromCssStyleString:(NSString *)cssString; | ||
|
||
@end |
64 changes: 64 additions & 0 deletions
64
Source/TypeConversion/Helpers/TyphoonColorConversionUtils.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// TYPHOON FRAMEWORK | ||
// Copyright 2015, Typhoon Framework Contributors | ||
// All Rights Reserved. | ||
// | ||
// NOTICE: The authors permit you to use, modify, and distribute this file | ||
// in accordance with the terms of the license agreement accompanying it. | ||
// | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
#import "TyphoonColorConversionUtils.h" | ||
|
||
@implementation TyphoonColorConversionUtils | ||
|
||
+ (struct RGBA)colorFromHexString:(NSString *)hexString { | ||
hexString = | ||
[[hexString stringByReplacingOccurrencesOfString:@"#" withString:@""] stringByReplacingOccurrencesOfString:@"0x" withString:@""]; | ||
|
||
unsigned int red, green, blue, alpha; | ||
if ([hexString length] == 6) { | ||
sscanf([hexString UTF8String], "%02X%02X%02X", &red, &green, &blue); | ||
alpha = 255; | ||
} | ||
else if ([hexString length] == 8) { | ||
sscanf([hexString UTF8String], "%02X%02X%02X%02X", &alpha, &red, &green, &blue); | ||
} | ||
else { | ||
[NSException raise:NSInvalidArgumentException format:@"%@ requires a six or eight digit hex string.", | ||
NSStringFromClass([self class])]; | ||
} | ||
return [self colorFromRed:red green:green blue:blue alpha:(CGFloat)(alpha / 255.0)]; | ||
} | ||
|
||
+ (struct RGBA)colorFromCssStyleString:(NSString *)cssString { | ||
NSArray *colorComponents = [cssString componentsSeparatedByString:@","]; | ||
|
||
unsigned int red, green, blue; | ||
float alpha; | ||
if ([colorComponents count] == 3) { | ||
sscanf([cssString UTF8String], "%d,%d,%d", &red, &green, &blue); | ||
alpha = 1.0; | ||
} | ||
else if ([colorComponents count] == 4) { | ||
sscanf([cssString UTF8String], "%d,%d,%d,%f", &red, &green, &blue, &alpha); | ||
} | ||
else { | ||
[NSException raise:NSInvalidArgumentException format:@"%@ requires css style format UIColor(r,g,b) or UIColor(r,g,b,a).", | ||
NSStringFromClass([self class])]; | ||
} | ||
return [self colorFromRed:red green:green blue:blue alpha:alpha]; | ||
} | ||
|
||
+ (struct RGBA)colorFromRed:(NSUInteger)red green:(NSUInteger)green blue:(NSUInteger)blue alpha:(CGFloat)alpha | ||
{ | ||
struct RGBA color; | ||
color.red = (CGFloat)red / 255.0; | ||
color.green = (CGFloat)green / 255.0; | ||
color.blue = (CGFloat)blue / 255.0; | ||
color.alpha = (CGFloat)alpha; | ||
return color; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// TYPHOON FRAMEWORK | ||
// Copyright 2015, Typhoon Framework Contributors | ||
// All Rights Reserved. | ||
// | ||
// NOTICE: The authors permit you to use, modify, and distribute this file | ||
// in accordance with the terms of the license agreement accompanying it. | ||
// | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
/** | ||
* A collection of helper methods for type conversion purposes | ||
*/ | ||
@interface TyphoonTypeConversionUtils : NSObject | ||
|
||
/** | ||
* Returns the type from the text, e.g. NSURL for NSURL(http://typhoonframework.org) | ||
*/ | ||
+ (NSString *)typeFromTextValue:(NSString *)textValue; | ||
|
||
/** | ||
* Returns the type from the text, e.g. http://typhoonframework.org for NSURL(http://typhoonframework.org) | ||
*/ | ||
+ (NSString *)textWithoutTypeFromTextValue:(NSString *)textValue; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// TYPHOON FRAMEWORK | ||
// Copyright 2015, Typhoon Framework Contributors | ||
// All Rights Reserved. | ||
// | ||
// NOTICE: The authors permit you to use, modify, and distribute this file | ||
// in accordance with the terms of the license agreement accompanying it. | ||
// | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
#import "TyphoonTypeConversionUtils.h" | ||
|
||
@implementation TyphoonTypeConversionUtils | ||
|
||
+ (NSString *)typeFromTextValue:(NSString *)textValue | ||
{ | ||
NSString *type = nil; | ||
|
||
NSRange openBraceRange = [textValue rangeOfString:@"("]; | ||
BOOL hasBraces = [textValue hasSuffix:@")"] && openBraceRange.location != NSNotFound; | ||
if (hasBraces) { | ||
type = [textValue substringToIndex:openBraceRange.location]; | ||
} | ||
|
||
return type; | ||
} | ||
|
||
+ (NSString *)textWithoutTypeFromTextValue:(NSString *)textValue | ||
{ | ||
NSString *result = textValue; | ||
|
||
NSRange openBraceRange = [textValue rangeOfString:@"("]; | ||
BOOL hasBraces = [textValue hasSuffix:@")"] && openBraceRange.location != NSNotFound; | ||
|
||
if (hasBraces) { | ||
NSRange range = NSMakeRange(openBraceRange.location + openBraceRange.length, 0); | ||
range.length = [textValue length] - range.location - 1; | ||
result = [textValue substringWithRange:range]; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.