GTMNSString+HTML.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // GTMNSString+HTML.h
  3. // Dealing with NSStrings that contain HTML
  4. //
  5. // Copyright 2006-2008 Google Inc.
  6. //
  7. // Licensed under the Apache License, Version 2.0 (the "License"); you may not
  8. // use this file except in compliance with the License. You may obtain a copy
  9. // of the License at
  10. //
  11. // http://www.apache.org/licenses/LICENSE-2.0
  12. //
  13. // Unless required by applicable law or agreed to in writing, software
  14. // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. // License for the specific language governing permissions and limitations under
  17. // the License.
  18. //
  19. #import <Foundation/Foundation.h>
  20. /// Utilities for NSStrings containing HTML
  21. @interface NSString (GTMNSStringHTMLAdditions)
  22. /// Get a string where internal characters that need escaping for HTML are escaped
  23. //
  24. /// For example, '&' become '&amp;'. This will only cover characters from table
  25. /// A.2.2 of http://www.w3.org/TR/xhtml1/dtds.html#a_dtd_Special_characters
  26. /// which is what you want for a unicode encoded webpage. If you have a ascii
  27. /// or non-encoded webpage, please use stringByEscapingAsciiHTML which will
  28. /// encode all characters.
  29. ///
  30. /// For obvious reasons this call is only safe once.
  31. //
  32. // Returns:
  33. // Autoreleased NSString
  34. //
  35. - (NSString *)gtm_stringByEscapingForHTML;
  36. /// Get a string where internal characters that need escaping for HTML are escaped
  37. //
  38. /// For example, '&' become '&amp;'
  39. /// All non-mapped characters (unicode that don't have a &keyword; mapping)
  40. /// will be converted to the appropriate &#xxx; value. If your webpage is
  41. /// unicode encoded (UTF16 or UTF8) use stringByEscapingHTML instead as it is
  42. /// faster, and produces less bloated and more readable HTML (as long as you
  43. /// are using a unicode compliant HTML reader).
  44. ///
  45. /// For obvious reasons this call is only safe once.
  46. //
  47. // Returns:
  48. // Autoreleased NSString
  49. //
  50. - (NSString *)gtm_stringByEscapingForAsciiHTML;
  51. /// Get a string where internal characters that are escaped for HTML are unescaped
  52. //
  53. /// For example, '&amp;' becomes '&'
  54. /// Handles &#32; and &#x32; cases as well
  55. ///
  56. // Returns:
  57. // Autoreleased NSString
  58. //
  59. - (NSString *)gtm_stringByUnescapingFromHTML;
  60. @end