Açıklama Yok

ConvertToCommonEmoticonsHelper.m 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. //
  2. // ConvertToCommonEmoticonsHelper.m
  3. // ChatDemo-UI2.0
  4. //
  5. // Created by dujiepeng on 14-6-30.
  6. // Copyright (c) 2014年 dujiepeng. All rights reserved.
  7. //
  8. #import "ConvertToCommonEmoticonsHelper.h"
  9. #import "Emoji.h"
  10. @implementation ConvertToCommonEmoticonsHelper
  11. #pragma mark - emotics
  12. + (NSString *)convertToCommonEmoticons:(NSString *)text {
  13. int allEmoticsCount = (int)[Emoji allEmoji].count;
  14. NSMutableString *retText = [[NSMutableString alloc] initWithString:text];
  15. for(int i=0; i<allEmoticsCount; ++i) {
  16. NSRange range;
  17. range.location = 0;
  18. range.length = retText.length;
  19. [retText replaceOccurrencesOfString:@"😊"
  20. withString:@"[):]"
  21. options:NSLiteralSearch
  22. range:range];
  23. range.location = 0;
  24. range.length = retText.length;
  25. [retText replaceOccurrencesOfString:@"😃"
  26. withString:@"[:D]"
  27. options:NSLiteralSearch
  28. range:range];
  29. range.location = 0;
  30. range.length = retText.length;
  31. [retText replaceOccurrencesOfString:@"😉"
  32. withString:@"[;)]"
  33. options:NSLiteralSearch
  34. range:range];
  35. range.location = 0;
  36. range.length = retText.length;
  37. [retText replaceOccurrencesOfString:@"😮"
  38. withString:@"[:-o]"
  39. options:NSLiteralSearch
  40. range:range];
  41. range.location = 0;
  42. range.length = retText.length;
  43. [retText replaceOccurrencesOfString:@"😋"
  44. withString:@"[:p]"
  45. options:NSLiteralSearch
  46. range:range];
  47. range.location = 0;
  48. range.length = retText.length;
  49. [retText replaceOccurrencesOfString:@"😎"
  50. withString:@"[(H)]"
  51. options:NSLiteralSearch
  52. range:range];
  53. range.location = 0;
  54. range.length = retText.length;
  55. [retText replaceOccurrencesOfString:@"😡"
  56. withString:@"[:@]"
  57. options:NSLiteralSearch
  58. range:range];
  59. range.location = 0;
  60. range.length = retText.length;
  61. [retText replaceOccurrencesOfString:@"😖"
  62. withString:@"[:s]"
  63. options:NSLiteralSearch
  64. range:range];
  65. range.location = 0;
  66. range.length = retText.length;
  67. [retText replaceOccurrencesOfString:@"😳"
  68. withString:@"[:$]"
  69. options:NSLiteralSearch
  70. range:range];
  71. range.location = 0;
  72. range.length = retText.length;
  73. [retText replaceOccurrencesOfString:@"😞"
  74. withString:@"[:(]"
  75. options:NSLiteralSearch
  76. range:range];
  77. range.location = 0;
  78. range.length = retText.length;
  79. [retText replaceOccurrencesOfString:@"😭"
  80. withString:@"[:'(]"
  81. options:NSLiteralSearch
  82. range:range];
  83. range.location = 0;
  84. range.length = retText.length;
  85. [retText replaceOccurrencesOfString:@"😐"
  86. withString:@"[:|]"
  87. options:NSLiteralSearch
  88. range:range];
  89. range.location = 0;
  90. range.length = retText.length;
  91. [retText replaceOccurrencesOfString:@"😇"
  92. withString:@"[(a)]"
  93. options:NSLiteralSearch
  94. range:range];
  95. range.location = 0;
  96. range.length = retText.length;
  97. [retText replaceOccurrencesOfString:@"😬"
  98. withString:@"[8o|]"
  99. options:NSLiteralSearch
  100. range:range];
  101. range.location = 0;
  102. range.length = retText.length;
  103. [retText replaceOccurrencesOfString:@"😆"
  104. withString:@"[8-|]"
  105. options:NSLiteralSearch
  106. range:range];
  107. range.location = 0;
  108. range.length = retText.length;
  109. [retText replaceOccurrencesOfString:@"😱"
  110. withString:@"[+o(]"
  111. options:NSLiteralSearch
  112. range:range];
  113. range.location = 0;
  114. range.length = retText.length;
  115. [retText replaceOccurrencesOfString:@"🎅"
  116. withString:@"[<o)]"
  117. options:NSLiteralSearch
  118. range:range];
  119. range.location = 0;
  120. range.length = retText.length;
  121. [retText replaceOccurrencesOfString:@"😴"
  122. withString:@"[|-)]"
  123. options:NSLiteralSearch
  124. range:range];
  125. range.location = 0;
  126. range.length = retText.length;
  127. [retText replaceOccurrencesOfString:@"😕"
  128. withString:@"[*-)]"
  129. options:NSLiteralSearch
  130. range:range];
  131. range.location = 0;
  132. range.length = retText.length;
  133. [retText replaceOccurrencesOfString:@"😷"
  134. withString:@"[:-#]"
  135. options:NSLiteralSearch
  136. range:range];
  137. range.location = 0;
  138. range.length = retText.length;
  139. [retText replaceOccurrencesOfString:@"😯"
  140. withString:@"[:-*]"
  141. options:NSLiteralSearch
  142. range:range];
  143. range.location = 0;
  144. range.length = retText.length;
  145. [retText replaceOccurrencesOfString:@"😏"
  146. withString:@"[^o)]"
  147. options:NSLiteralSearch
  148. range:range];
  149. range.location = 0;
  150. range.length = retText.length;
  151. [retText replaceOccurrencesOfString:@"😑"
  152. withString:@"[8-)]"
  153. options:NSLiteralSearch
  154. range:range];
  155. range.location = 0;
  156. range.length = retText.length;
  157. [retText replaceOccurrencesOfString:@"💖"
  158. withString:@"[(|)]"
  159. options:NSLiteralSearch
  160. range:range];
  161. range.location = 0;
  162. range.length = retText.length;
  163. [retText replaceOccurrencesOfString:@"💔"
  164. withString:@"[(u)]"
  165. options:NSLiteralSearch
  166. range:range];
  167. range.location = 0;
  168. range.length = retText.length;
  169. [retText replaceOccurrencesOfString:@"🌙"
  170. withString:@"[(S)]"
  171. options:NSLiteralSearch
  172. range:range];
  173. range.location = 0;
  174. range.length = retText.length;
  175. [retText replaceOccurrencesOfString:@"🌟"
  176. withString:@"[(*)]"
  177. options:NSLiteralSearch
  178. range:range];
  179. range.location = 0;
  180. range.length = retText.length;
  181. [retText replaceOccurrencesOfString:@"🌞"
  182. withString:@"[(#)]"
  183. options:NSLiteralSearch
  184. range:range];
  185. range.location = 0;
  186. range.length = retText.length;
  187. [retText replaceOccurrencesOfString:@"🌈"
  188. withString:@"[(R)]"
  189. options:NSLiteralSearch
  190. range:range];
  191. range.location = 0;
  192. range.length = retText.length;
  193. [retText replaceOccurrencesOfString:@"😚"
  194. withString:@"[(})]"
  195. options:NSLiteralSearch
  196. range:range];
  197. range.location = 0;
  198. range.length = retText.length;
  199. [retText replaceOccurrencesOfString:@"😍"
  200. withString:@"[({)]"
  201. options:NSLiteralSearch
  202. range:range];
  203. range.location = 0;
  204. range.length = retText.length;
  205. [retText replaceOccurrencesOfString:@"💋"
  206. withString:@"[(k)]"
  207. options:NSLiteralSearch
  208. range:range];
  209. range.location = 0;
  210. range.length = retText.length;
  211. [retText replaceOccurrencesOfString:@"🌹"
  212. withString:@"[(F)]"
  213. options:NSLiteralSearch
  214. range:range];
  215. range.location = 0;
  216. range.length = retText.length;
  217. [retText replaceOccurrencesOfString:@"🍂"
  218. withString:@"[(W)]"
  219. options:NSLiteralSearch
  220. range:range];
  221. range.location = 0;
  222. range.length = retText.length;
  223. [retText replaceOccurrencesOfString:@"👍"
  224. withString:@"[(D)]"
  225. options:NSLiteralSearch
  226. range:range];
  227. }
  228. return retText;
  229. }
  230. + (NSString *)convertToSystemEmoticons:(NSString *)text {
  231. int allEmoticsCount = (int)[Emoji allEmoji].count;
  232. NSMutableString *retText = [[NSMutableString alloc] initWithString:text];
  233. for(int i=0; i<allEmoticsCount; ++i) {
  234. NSRange range;
  235. range.location = 0;
  236. range.length = retText.length;
  237. [retText replaceOccurrencesOfString:@"[):]"
  238. withString:@"😊"
  239. options:NSLiteralSearch
  240. range:range];
  241. range.location = 0;
  242. range.length = retText.length;
  243. [retText replaceOccurrencesOfString:@"[:D]"
  244. withString:@"😃"
  245. options:NSLiteralSearch
  246. range:range];
  247. range.location = 0;
  248. range.length = retText.length;
  249. [retText replaceOccurrencesOfString:@"[;)]"
  250. withString:@"😉"
  251. options:NSLiteralSearch
  252. range:range];
  253. range.location = 0;
  254. range.length = retText.length;
  255. [retText replaceOccurrencesOfString:@"[:-o]"
  256. withString:@"😮"
  257. options:NSLiteralSearch
  258. range:range];
  259. range.location = 0;
  260. range.length = retText.length;
  261. [retText replaceOccurrencesOfString:@"[:p]"
  262. withString:@"😋"
  263. options:NSLiteralSearch
  264. range:range];
  265. range.location = 0;
  266. range.length = retText.length;
  267. [retText replaceOccurrencesOfString:@"[(H)]"
  268. withString:@"😎"
  269. options:NSLiteralSearch
  270. range:range];
  271. range.location = 0;
  272. range.length = retText.length;
  273. [retText replaceOccurrencesOfString:@"[:@]"
  274. withString:@"😡"
  275. options:NSLiteralSearch
  276. range:range];
  277. range.location = 0;
  278. range.length = retText.length;
  279. [retText replaceOccurrencesOfString:@"[:s]"
  280. withString:@"😖"
  281. options:NSLiteralSearch
  282. range:range];
  283. range.location = 0;
  284. range.length = retText.length;
  285. [retText replaceOccurrencesOfString:@"[:$]"
  286. withString:@"😳"
  287. options:NSLiteralSearch
  288. range:range];
  289. range.location = 0;
  290. range.length = retText.length;
  291. [retText replaceOccurrencesOfString:@"[:(]"
  292. withString:@"😞"
  293. options:NSLiteralSearch
  294. range:range];
  295. range.location = 0;
  296. range.length = retText.length;
  297. [retText replaceOccurrencesOfString:@"[:'(]"
  298. withString:@"😭"
  299. options:NSLiteralSearch
  300. range:range];
  301. range.location = 0;
  302. range.length = retText.length;
  303. [retText replaceOccurrencesOfString:@"[:|]"
  304. withString:@"😐"
  305. options:NSLiteralSearch
  306. range:range];
  307. range.location = 0;
  308. range.length = retText.length;
  309. [retText replaceOccurrencesOfString:@"[(a)]"
  310. withString:@"😇"
  311. options:NSLiteralSearch
  312. range:range];
  313. range.location = 0;
  314. range.length = retText.length;
  315. [retText replaceOccurrencesOfString:@"[8o|]"
  316. withString:@"😬"
  317. options:NSLiteralSearch
  318. range:range];
  319. range.location = 0;
  320. range.length = retText.length;
  321. [retText replaceOccurrencesOfString:@"[8-|]"
  322. withString:@"😆"
  323. options:NSLiteralSearch
  324. range:range];
  325. range.location = 0;
  326. range.length = retText.length;
  327. [retText replaceOccurrencesOfString:@"[+o(]"
  328. withString:@"😱"
  329. options:NSLiteralSearch
  330. range:range];
  331. range.location = 0;
  332. range.length = retText.length;
  333. [retText replaceOccurrencesOfString:@"[<o)]"
  334. withString:@"🎅"
  335. options:NSLiteralSearch
  336. range:range];
  337. range.location = 0;
  338. range.length = retText.length;
  339. [retText replaceOccurrencesOfString:@"[|-)]"
  340. withString:@"😴"
  341. options:NSLiteralSearch
  342. range:range];
  343. range.location = 0;
  344. range.length = retText.length;
  345. [retText replaceOccurrencesOfString:@"[*-)]"
  346. withString:@"😕"
  347. options:NSLiteralSearch
  348. range:range];
  349. range.location = 0;
  350. range.length = retText.length;
  351. [retText replaceOccurrencesOfString:@"[:-#]"
  352. withString:@"😷"
  353. options:NSLiteralSearch
  354. range:range];
  355. range.location = 0;
  356. range.length = retText.length;
  357. [retText replaceOccurrencesOfString:@"[:-*]"
  358. withString:@"😯"
  359. options:NSLiteralSearch
  360. range:range];
  361. range.location = 0;
  362. range.length = retText.length;
  363. [retText replaceOccurrencesOfString:@"[^o)]"
  364. withString:@"😏"
  365. options:NSLiteralSearch
  366. range:range];
  367. range.location = 0;
  368. range.length = retText.length;
  369. [retText replaceOccurrencesOfString:@"[8-)]"
  370. withString:@"😑"
  371. options:NSLiteralSearch
  372. range:range];
  373. range.location = 0;
  374. range.length = retText.length;
  375. [retText replaceOccurrencesOfString:@"[(|)]"
  376. withString:@"💖"
  377. options:NSLiteralSearch
  378. range:range];
  379. range.location = 0;
  380. range.length = retText.length;
  381. [retText replaceOccurrencesOfString:@"[(u)]"
  382. withString:@"💔"
  383. options:NSLiteralSearch
  384. range:range];
  385. range.location = 0;
  386. range.length = retText.length;
  387. [retText replaceOccurrencesOfString:@"[(S)]"
  388. withString:@"🌙"
  389. options:NSLiteralSearch
  390. range:range];
  391. range.location = 0;
  392. range.length = retText.length;
  393. [retText replaceOccurrencesOfString:@"[(*)]"
  394. withString:@"🌟"
  395. options:NSLiteralSearch
  396. range:range];
  397. range.location = 0;
  398. range.length = retText.length;
  399. [retText replaceOccurrencesOfString:@"[(#)]"
  400. withString:@"🌞"
  401. options:NSLiteralSearch
  402. range:range];
  403. range.location = 0;
  404. range.length = retText.length;
  405. [retText replaceOccurrencesOfString:@"[(R)]"
  406. withString:@"🌈"
  407. options:NSLiteralSearch
  408. range:range];
  409. range.location = 0;
  410. range.length = retText.length;
  411. [retText replaceOccurrencesOfString:@"[(})]"
  412. withString:@"😚"
  413. options:NSLiteralSearch
  414. range:range];
  415. range.location = 0;
  416. range.length = retText.length;
  417. [retText replaceOccurrencesOfString:@"[({)]"
  418. withString:@"😍"
  419. options:NSLiteralSearch
  420. range:range];
  421. range.location = 0;
  422. range.length = retText.length;
  423. [retText replaceOccurrencesOfString:@"[(k)]"
  424. withString:@"💋"
  425. options:NSLiteralSearch
  426. range:range];
  427. range.location = 0;
  428. range.length = retText.length;
  429. [retText replaceOccurrencesOfString:@"[(F)]"
  430. withString:@"🌹"
  431. options:NSLiteralSearch
  432. range:range];
  433. range.location = 0;
  434. range.length = retText.length;
  435. [retText replaceOccurrencesOfString:@"[(W)]"
  436. withString:@"🍂"
  437. options:NSLiteralSearch
  438. range:range];
  439. range.location = 0;
  440. range.length = retText.length;
  441. [retText replaceOccurrencesOfString:@"[(D)]"
  442. withString:@"👍"
  443. options:NSLiteralSearch
  444. range:range];
  445. }
  446. return retText;
  447. }
  448. @end