123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- //
- // NSString+YLString.h
- // YoungCatogory
- //
- // Created by kuxuan on 2017/7/12.
- // Copyright © 2017年 kuxuan. All rights reserved.
- //
- #import <Foundation/Foundation.h>
- #import <UIKit/UIKit.h>
- @interface NSString (YLString)
- /** Creates a new string that contains a generated UUID.
-
- @return The path to the app's Caches folder.
- */
- + (NSString *_Nonnull)stringWithUUID;
- /** creates an MD5
-
- @return returns an MD5 hash for the receiver.
- */
- - (NSString *_Nonnull)md5;
- /** Determines the path to the Library/Caches folder in the current application's sandbox.
-
- The return value is cached on the first call.
-
- @return The path to the app's Caches folder.
- */
- + (NSString *_Nullable)cachesPath;
- /** Determines the path to the Documents folder in the current application's sandbox.
-
- The return value is cached on the first call.
-
- @return The path to the app's Documents folder.
- */
- + (NSString *_Nonnull)documentsPath;
- /**-------------------------------------------------------------------------------------
- @name Getting Temporary Paths
- ---------------------------------------------------------------------------------------
- */
- /** Determines the path for temporary files in the current application's sandbox.
-
- The return value is cached on the first call. This value is different in Simulator than on the actual device. In Simulator you get a reference to /tmp wheras on iOS devices it is a special folder inside the application folder.
-
- @return The path to the app's folder for temporary files.
- */
- + (NSString *_Nullable)temporaryPath;
- /**
- * Check if self has the given substring in case-sensitive
- *
- * @param substring The substring to be searched
- *
- * @return Returns YES if founded, NO if not
- */
- - (BOOL)hasString:(NSString * _Nonnull)substring;
- /**
- * Check if self has the given substring specifying if is case-sensitive or not
- *
- * @param substring The substring to be searched
- * @param caseSensitive If the search has to be case-sensitive or not
- *
- * @return Returns YES if founded, NO if not
- */
- - (BOOL)hasString:(NSString * _Nonnull)substring
- caseSensitive:(BOOL)caseSensitive;
- /**
- * Check if self is an email
- *
- * @return Returns YES if it's an email, NO if not
- */
- - (BOOL)isEmail;
- /**
- * Check if the given string is an email
- *
- * @param email The string to be checked
- *
- * @return Returns YES if it's an email, NO if not
- */
- + (BOOL)isEmail:(NSString * _Nonnull)email;
- /**
- * Convert a string to UTF8
- *
- * @param string String to be converted
- *
- * @return Returns the converted string
- */
- + (NSString * _Nonnull)convertToUTF8Entities:(NSString * _Nonnull)string;
- /**
- * Encode the given string to Base64
- *
- * @param string String to encode
- *
- * @return Returns the encoded string
- */
- + (NSString * _Nonnull)encodeToBase64:(NSString * _Nonnull)string;
- /**
- * Encode the given string to Base64
- *
- * @return Returns the encoded string
- */
- - (NSString * _Nonnull)encodeToBase64;
- /**
- * Decode the given Base64 to string
- *
- * @param string String to decode
- *
- * @return Returns the decoded string
- */
- + (NSString * _Nonnull)decodeBase64:(NSString * _Nonnull)string;
- /**
- * Decode the given Base64 to string
- *
- * @return Returns the decoded string
- */
- - (NSString * _Nonnull)decodeBase64;
- /**
- * Convert the given NSString to NSData
- *
- * @param string The NSString to be converted
- *
- * @return Returns the converted NSString as NSData
- */
- + (NSData * _Nonnull)convertToNSData:(NSString * _Nonnull)string;
- /**
- * Convert self to a NSData
- *
- * @return Returns self as NSData
- */
- - (NSData * _Nonnull)convertToNSData;
- /**
- * Conver self to a capitalized string.
- * Example: "This is a Test" will return "This is a test" and "this is a test" will return "This is a test"
- *
- * @return Returns the capitalized sentence string
- */
- - (NSString * _Nonnull)sentenceCapitalizedString;
- /**
- * Returns a human legible string from a timestamp
- *
- * @return Returns a human legible string from a timestamp
- */
- - (NSString * _Nonnull)dateFromTimestamp;
- /**
- * Encode self to an encoded url string
- *
- * @return Returns the encoded NSString
- */
- - (NSString * _Nonnull)urlEncode DEPRECATED_MSG_ATTRIBUTE("Use -URLEncode");
- /**
- * Encode self to an encoded url string
- *
- * @return Returns the encoded NSString
- */
- - (NSString * _Nonnull)URLEncode;
- /**
- * Remove double or more duplicated spaces
- *
- * @return String without additional spaces
- */
- - (NSString * _Nonnull)removeExtraSpaces;
- /**
- * Returns a new string containing matching regular expressions replaced with the template string
- *
- * @param regexString The regex string
- * @param replacement The replacement string
- *
- * @return Returns a new string containing matching regular expressions replaced with the template string
- */
- - (NSString * _Nonnull)stringByReplacingWithRegex:(NSString * _Nonnull)regexString
- withString:(NSString * _Nonnull)replacement;
- /**
- * Convert HEX string (separated by space) to "usual" characters string.
- * Example: "68 65 6c 6c 6f" -> "hello"
- *
- * @return Readable string
- */
- - (NSString * _Nonnull)HEXToString;
- /**
- * Convert string to HEX string.
- * Example: "hello" -> "68656c6c6f"
- *
- * @return HEX string
- */
- - (NSString * _Nonnull)stringToHEX;
- /**
- * Used to create an UUID as NSString
- *
- * @return Returns the created UUID string
- */
- + (NSString * _Nonnull)generateUUID;
- /**
- * Returns if self is a valid UUID or not
- *
- * @return Returns if self is a valid UUID or not
- */
- - (BOOL)isUUID;
- /**
- * Returns if self is a valid UUID for APNS (Apple Push Notification System) or not
- *
- * @return Returns if self is a valid UUID for APNS (Apple Push Notification System) or not
- */
- - (BOOL)isUUIDForAPNS;
- /**
- * Converts self to an UUID APNS valid (No "<>" or "-" or spaces)
- *
- * @return Converts self to an UUID APNS valid (No "<>" or "-" or spaces)
- */
- - (NSString * _Nonnull)convertToAPNSUUID;
- /**
- * Remove all white space
- * @return Returns string which remove all white space
- */
- - (NSString *_Nullable)trimAllWhiteSpace;
- /**
- * Used to calculate text height for max width and font
- *
- * @param width Max width to fit text
- * @param font Font used in text
- *
- * @return Returns the calculated height of string within width using given font
- */
- - (CGFloat)heightForWidth:(float)width
- andFont:(UIFont * _Nonnull)font;
- + (NSString *_Nullable)getAppName;
- @end
|