No Description

NSString+YLString.h 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. //
  2. // NSString+YLString.h
  3. // YoungCatogory
  4. //
  5. // Created by kuxuan on 2017/7/12.
  6. // Copyright © 2017年 kuxuan. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import <UIKit/UIKit.h>
  10. @interface NSString (YLString)
  11. /** Creates a new string that contains a generated UUID.
  12. @return The path to the app's Caches folder.
  13. */
  14. + (NSString *_Nonnull)stringWithUUID;
  15. /** creates an MD5
  16. @return returns an MD5 hash for the receiver.
  17. */
  18. - (NSString *_Nonnull)md5;
  19. /** Determines the path to the Library/Caches folder in the current application's sandbox.
  20. The return value is cached on the first call.
  21. @return The path to the app's Caches folder.
  22. */
  23. + (NSString *_Nullable)cachesPath;
  24. /** Determines the path to the Documents folder in the current application's sandbox.
  25. The return value is cached on the first call.
  26. @return The path to the app's Documents folder.
  27. */
  28. + (NSString *_Nonnull)documentsPath;
  29. /**-------------------------------------------------------------------------------------
  30. @name Getting Temporary Paths
  31. ---------------------------------------------------------------------------------------
  32. */
  33. /** Determines the path for temporary files in the current application's sandbox.
  34. 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.
  35. @return The path to the app's folder for temporary files.
  36. */
  37. + (NSString *_Nullable)temporaryPath;
  38. /**
  39. * Check if self has the given substring in case-sensitive
  40. *
  41. * @param substring The substring to be searched
  42. *
  43. * @return Returns YES if founded, NO if not
  44. */
  45. - (BOOL)hasString:(NSString * _Nonnull)substring;
  46. /**
  47. * Check if self has the given substring specifying if is case-sensitive or not
  48. *
  49. * @param substring The substring to be searched
  50. * @param caseSensitive If the search has to be case-sensitive or not
  51. *
  52. * @return Returns YES if founded, NO if not
  53. */
  54. - (BOOL)hasString:(NSString * _Nonnull)substring
  55. caseSensitive:(BOOL)caseSensitive;
  56. /**
  57. * Check if self is an email
  58. *
  59. * @return Returns YES if it's an email, NO if not
  60. */
  61. - (BOOL)isEmail;
  62. /**
  63. * Check if the given string is an email
  64. *
  65. * @param email The string to be checked
  66. *
  67. * @return Returns YES if it's an email, NO if not
  68. */
  69. + (BOOL)isEmail:(NSString * _Nonnull)email;
  70. /**
  71. * Convert a string to UTF8
  72. *
  73. * @param string String to be converted
  74. *
  75. * @return Returns the converted string
  76. */
  77. + (NSString * _Nonnull)convertToUTF8Entities:(NSString * _Nonnull)string;
  78. /**
  79. * Encode the given string to Base64
  80. *
  81. * @param string String to encode
  82. *
  83. * @return Returns the encoded string
  84. */
  85. + (NSString * _Nonnull)encodeToBase64:(NSString * _Nonnull)string;
  86. /**
  87. * Encode the given string to Base64
  88. *
  89. * @return Returns the encoded string
  90. */
  91. - (NSString * _Nonnull)encodeToBase64;
  92. /**
  93. * Decode the given Base64 to string
  94. *
  95. * @param string String to decode
  96. *
  97. * @return Returns the decoded string
  98. */
  99. + (NSString * _Nonnull)decodeBase64:(NSString * _Nonnull)string;
  100. /**
  101. * Decode the given Base64 to string
  102. *
  103. * @return Returns the decoded string
  104. */
  105. - (NSString * _Nonnull)decodeBase64;
  106. /**
  107. * Convert the given NSString to NSData
  108. *
  109. * @param string The NSString to be converted
  110. *
  111. * @return Returns the converted NSString as NSData
  112. */
  113. + (NSData * _Nonnull)convertToNSData:(NSString * _Nonnull)string;
  114. /**
  115. * Convert self to a NSData
  116. *
  117. * @return Returns self as NSData
  118. */
  119. - (NSData * _Nonnull)convertToNSData;
  120. /**
  121. * Conver self to a capitalized string.
  122. * Example: "This is a Test" will return "This is a test" and "this is a test" will return "This is a test"
  123. *
  124. * @return Returns the capitalized sentence string
  125. */
  126. - (NSString * _Nonnull)sentenceCapitalizedString;
  127. /**
  128. * Returns a human legible string from a timestamp
  129. *
  130. * @return Returns a human legible string from a timestamp
  131. */
  132. - (NSString * _Nonnull)dateFromTimestamp;
  133. /**
  134. * Encode self to an encoded url string
  135. *
  136. * @return Returns the encoded NSString
  137. */
  138. - (NSString * _Nonnull)urlEncode DEPRECATED_MSG_ATTRIBUTE("Use -URLEncode");
  139. /**
  140. * Encode self to an encoded url string
  141. *
  142. * @return Returns the encoded NSString
  143. */
  144. - (NSString * _Nonnull)URLEncode;
  145. /**
  146. * Remove double or more duplicated spaces
  147. *
  148. * @return String without additional spaces
  149. */
  150. - (NSString * _Nonnull)removeExtraSpaces;
  151. /**
  152. * Returns a new string containing matching regular expressions replaced with the template string
  153. *
  154. * @param regexString The regex string
  155. * @param replacement The replacement string
  156. *
  157. * @return Returns a new string containing matching regular expressions replaced with the template string
  158. */
  159. - (NSString * _Nonnull)stringByReplacingWithRegex:(NSString * _Nonnull)regexString
  160. withString:(NSString * _Nonnull)replacement;
  161. /**
  162. * Convert HEX string (separated by space) to "usual" characters string.
  163. * Example: "68 65 6c 6c 6f" -> "hello"
  164. *
  165. * @return Readable string
  166. */
  167. - (NSString * _Nonnull)HEXToString;
  168. /**
  169. * Convert string to HEX string.
  170. * Example: "hello" -> "68656c6c6f"
  171. *
  172. * @return HEX string
  173. */
  174. - (NSString * _Nonnull)stringToHEX;
  175. /**
  176. * Used to create an UUID as NSString
  177. *
  178. * @return Returns the created UUID string
  179. */
  180. + (NSString * _Nonnull)generateUUID;
  181. /**
  182. * Returns if self is a valid UUID or not
  183. *
  184. * @return Returns if self is a valid UUID or not
  185. */
  186. - (BOOL)isUUID;
  187. /**
  188. * Returns if self is a valid UUID for APNS (Apple Push Notification System) or not
  189. *
  190. * @return Returns if self is a valid UUID for APNS (Apple Push Notification System) or not
  191. */
  192. - (BOOL)isUUIDForAPNS;
  193. /**
  194. * Converts self to an UUID APNS valid (No "<>" or "-" or spaces)
  195. *
  196. * @return Converts self to an UUID APNS valid (No "<>" or "-" or spaces)
  197. */
  198. - (NSString * _Nonnull)convertToAPNSUUID;
  199. /**
  200. * Remove all white space
  201. * @return Returns string which remove all white space
  202. */
  203. - (NSString *_Nullable)trimAllWhiteSpace;
  204. /**
  205. * Used to calculate text height for max width and font
  206. *
  207. * @param width Max width to fit text
  208. * @param font Font used in text
  209. *
  210. * @return Returns the calculated height of string within width using given font
  211. */
  212. - (CGFloat)heightForWidth:(float)width
  213. andFont:(UIFont * _Nonnull)font;
  214. + (NSString *_Nullable)getAppName;
  215. @end