NSString(FWEncode)
@interface NSString (FWEncode)
#pragma mark - Json
/**
Foundation对象编码为json字符串
@param object 编码对象
@return json字符串
*/
+ (nullable NSString *)fw_jsonEncode:(id)object NS_REFINED_FOR_SWIFT;
/**
* json字符串解码为Foundation对象
*
* @return Foundation对象
*/
- (nullable id)fw_jsonDecode NS_REFINED_FOR_SWIFT;
#pragma mark - Base64
/**
* base64编码
*
* @return base64字符串
*/
- (nullable NSString *)fw_base64Encode NS_REFINED_FOR_SWIFT;
/**
* base64解码
*
* @return 原字符串
*/
- (nullable NSString *)fw_base64Decode NS_REFINED_FOR_SWIFT;
#pragma mark - Unicode
/**
* 计算长度,中文为1,英文为0.5
*/
- (NSUInteger)fw_unicodeLength NS_REFINED_FOR_SWIFT;
/**
* 截取字符串,中文为1,英文为0.5
*
* @param length 截取长度
*/
- (NSString *)fw_unicodeSubstring:(NSUInteger)length NS_REFINED_FOR_SWIFT;
/**
* Unicode中文编码,将中文转换成Unicode字符串(如\u7E8C)
*
* @return Unicode字符串
*/
- (NSString *)fw_unicodeEncode NS_REFINED_FOR_SWIFT;
/**
* Unicode中文解码,将Unicode字符串(如\u7E8C)转换成中文
*
* @return 中文字符串
*/
- (NSString *)fw_unicodeDecode NS_REFINED_FOR_SWIFT;
#pragma mark - Url
/**
* url参数编码,适用于query参数编码
* 示例:http://test.com?id=我是中文 =>
* http%3A%2F%2Ftest.com%3Fid%3D%E6%88%91%E6%98%AF%E4%B8%AD%E6%96%87
*
* @return url编码字符串
*/
- (nullable NSString *)fw_urlEncodeComponent NS_REFINED_FOR_SWIFT;
/**
* url参数解码,适用于query参数解码
* 示例:http%3A%2F%2Ftest.com%3Fid%3D%E6%88%91%E6%98%AF%E4%B8%AD%E6%96%87 =>
* http://test.com?id=我是中文
*
* @return 原字符串
*/
- (nullable NSString *)fw_urlDecodeComponent NS_REFINED_FOR_SWIFT;
/**
* url编码,适用于整个url编码
* 示例:http://test.com?id=我是中文 =>
* http://test.com?id=%E6%88%91%E6%98%AF%E4%B8%AD%E6%96%87
*
* @return url编码地址
*/
- (nullable NSString *)fw_urlEncode NS_REFINED_FOR_SWIFT;
/**
* url解码,适用于整个url解码
* 示例:http://test.com?id=%E6%88%91%E6%98%AF%E4%B8%AD%E6%96%87 =>
* http://test.com?id=我是中文
*
* @return 原url地址
*/
- (nullable NSString *)fw_urlDecode NS_REFINED_FOR_SWIFT;
#pragma mark - Query
/**
* 字典编码为URL参数字符串
*/
+ (NSString *)fw_queryEncode:(NSDictionary<NSString *, id> *)dictionary NS_REFINED_FOR_SWIFT;
/**
* URL参数字符串解码为字典,支持完整URL
*/
- (NSDictionary<NSString *, NSString *> *)fw_queryDecode NS_REFINED_FOR_SWIFT;
#pragma mark - Md5
/**
* md5编码
*
* @return md5字符串
*/
- (NSString *)fw_md5Encode NS_REFINED_FOR_SWIFT;
/**
* 文件md5编码
*
* @return md5字符串
*/
- (nullable NSString *)fw_md5EncodeFile NS_REFINED_FOR_SWIFT;
#pragma mark - Helper
/**
去掉空白字符
*/
@property (nonatomic, copy, readonly) NSString *fw_trimString NS_REFINED_FOR_SWIFT;
/**
首字母大写
*/
@property (nonatomic, copy, readonly) NSString *fw_ucfirstString NS_REFINED_FOR_SWIFT;
/**
首字母小写
*/
@property (nonatomic, copy, readonly) NSString *fw_lcfirstString NS_REFINED_FOR_SWIFT;
/**
驼峰转下划线
*/
@property (nonatomic, copy, readonly) NSString *fw_underlineString NS_REFINED_FOR_SWIFT;
/**
下划线转驼峰
*/
@property (nonatomic, copy, readonly) NSString *fw_camelString NS_REFINED_FOR_SWIFT;
/**
中文转拼音
*/
@property (nonatomic, copy, readonly) NSString *fw_pinyinString NS_REFINED_FOR_SWIFT;
/**
过滤JSON解码特殊字符
兼容\uD800-\uDFFF引起JSON解码报错3840问题,不报错时无需调用
规则:只允许以\uD800-\uDBFF高位开头,紧跟\uDC00-\uDFFF低位;其他全不允许
参考:https://github.com/SBJson/SBJson/blob/trunk/Classes/SBJson5StreamTokeniser.m
*/
@property (nonatomic, copy, readonly) NSString *fw_escapeJson NS_REFINED_FOR_SWIFT;
/**
转换为UTF8编码数据
*/
@property (nonatomic, strong, readonly, nullable) NSData *fw_utf8Data NS_REFINED_FOR_SWIFT;
/**
转换为NSURL
*/
@property (nonatomic, copy, readonly, nullable) NSURL *fw_url NS_REFINED_FOR_SWIFT;
/**
转换为NSNumber
*/
@property (nonatomic, readonly, nullable) NSNumber *fw_number NS_REFINED_FOR_SWIFT;
@end
Undocumented
-
Foundation对象编码为json字符串
Declaration
Objective-C
+ (nullable NSString *)fw_jsonEncode:(nonnull id)object;
Parameters
object
编码对象
Return Value
json字符串
-
json字符串解码为Foundation对象
Declaration
Objective-C
- (nullable id)fw_jsonDecode;
Return Value
Foundation对象
-
base64编码
Declaration
Objective-C
- (nullable NSString *)fw_base64Encode;
Return Value
base64字符串
-
base64解码
Declaration
Objective-C
- (nullable NSString *)fw_base64Decode;
Return Value
原字符串
-
计算长度,中文为1,英文为0.5
Declaration
Objective-C
- (NSUInteger)fw_unicodeLength;
-
截取字符串,中文为1,英文为0.5
Declaration
Objective-C
- (nonnull NSString *)fw_unicodeSubstring:(NSUInteger)length;
Parameters
length
截取长度
-
Unicode中文编码,将中文转换成Unicode字符串(如\u7E8C)
Declaration
Objective-C
- (nonnull NSString *)fw_unicodeEncode;
Return Value
Unicode字符串
-
Unicode中文解码,将Unicode字符串(如\u7E8C)转换成中文
Declaration
Objective-C
- (nonnull NSString *)fw_unicodeDecode;
Return Value
中文字符串
-
url参数编码,适用于query参数编码 示例:http://test.com?id=我是中文 => http%3A%2F%2Ftest.com%3Fid%3D%E6%88%91%E6%98%AF%E4%B8%AD%E6%96%87
Declaration
Objective-C
- (nullable NSString *)fw_urlEncodeComponent;
Return Value
url编码字符串
-
url参数解码,适用于query参数解码 示例:http%3A%2F%2Ftest.com%3Fid%3D%E6%88%91%E6%98%AF%E4%B8%AD%E6%96%87 => http://test.com?id=我是中文
Declaration
Objective-C
- (nullable NSString *)fw_urlDecodeComponent;
Return Value
原字符串
-
url编码,适用于整个url编码 示例:http://test.com?id=我是中文 => http://test.com?id=%E6%88%91%E6%98%AF%E4%B8%AD%E6%96%87
Declaration
Objective-C
- (nullable NSString *)fw_urlEncode;
Return Value
url编码地址
-
url解码,适用于整个url解码 示例:http://test.com?id=%E6%88%91%E6%98%AF%E4%B8%AD%E6%96%87 => http://test.com?id=我是中文
Declaration
Objective-C
- (nullable NSString *)fw_urlDecode;
Return Value
原url地址
-
字典编码为URL参数字符串
Declaration
Objective-C
+ (nonnull NSString *)fw_queryEncode: (nonnull NSDictionary<NSString *, id> *)dictionary;
-
URL参数字符串解码为字典,支持完整URL
Declaration
Objective-C
- (nonnull NSDictionary<NSString *, NSString *> *)fw_queryDecode;
-
md5编码
Declaration
Objective-C
- (nonnull NSString *)fw_md5Encode;
Return Value
md5字符串
-
文件md5编码
Declaration
Objective-C
- (nullable NSString *)fw_md5EncodeFile;
Return Value
md5字符串
-
去掉空白字符
Declaration
Objective-C
@property (nonatomic, copy, readonly) NS_REFINED_FOR_SWIFT NSString *fw_trimString;
-
首字母大写
Declaration
Objective-C
@property (nonatomic, copy, readonly) NS_REFINED_FOR_SWIFT NSString *fw_ucfirstString;
-
首字母小写
Declaration
Objective-C
@property (nonatomic, copy, readonly) NS_REFINED_FOR_SWIFT NSString *fw_lcfirstString;
-
驼峰转下划线
Declaration
Objective-C
@property (nonatomic, copy, readonly) NS_REFINED_FOR_SWIFT NSString *fw_underlineString;
-
下划线转驼峰
Declaration
Objective-C
@property (nonatomic, copy, readonly) NS_REFINED_FOR_SWIFT NSString *fw_camelString;
-
中文转拼音
Declaration
Objective-C
@property (nonatomic, copy, readonly) NS_REFINED_FOR_SWIFT NSString *fw_pinyinString;
-
过滤JSON解码特殊字符
兼容\uD800-\uDFFF引起JSON解码报错3840问题,不报错时无需调用 规则:只允许以\uD800-\uDBFF高位开头,紧跟\uDC00-\uDFFF低位;其他全不允许 参考:https://github.com/SBJson/SBJson/blob/trunk/Classes/SBJson5StreamTokeniser.m
Declaration
Objective-C
@property (nonatomic, copy, readonly) NS_REFINED_FOR_SWIFT NSString *fw_escapeJson;
-
转换为UTF8编码数据
Declaration
Objective-C
@property (nonatomic, strong, readonly, nullable) NSData *fw_utf8Data;
-
转换为NSURL
Declaration
Objective-C
@property (nonatomic, copy, readonly, nullable) NSURL *fw_url;
-
转换为NSNumber
Declaration
Objective-C
@property (nonatomic, readonly, nullable) NSNumber *fw_number;