All Projects β†’ alexisakers β†’ Htmlstring

alexisakers / Htmlstring

Licence: mit
Escape and unescape HTML entities in Swift

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Htmlstring

Tiny Utf8
Unicode (UTF-8) capable std::string
Stars: ✭ 322 (+170.59%)
Mutual labels:  decoder, string
Base62.js
πŸ”‘ A javascript Base62 encode/decoder for node.js
Stars: ✭ 108 (-9.24%)
Mutual labels:  decoder
Faad2
Freeware Advanced Audio (AAC) Decoder faad2 mirror
Stars: ✭ 82 (-31.09%)
Mutual labels:  decoder
Zswtaggedstring
Converts Strings into NSAttributedStrings using an HTML-like markup language.
Stars: ✭ 98 (-17.65%)
Mutual labels:  string
Decoder
δΈ€δΈͺη½‘η»œζ‘„εƒε€΄θ§£η η›‘ζŽ§εΉ³ε°
Stars: ✭ 86 (-27.73%)
Mutual labels:  decoder
Gifdec
small C GIF decoder
Stars: ✭ 100 (-15.97%)
Mutual labels:  decoder
String To Stream
Convert a string into a stream (streams2)
Stars: ✭ 75 (-36.97%)
Mutual labels:  string
Fuif
Free Universal Image Format
Stars: ✭ 115 (-3.36%)
Mutual labels:  decoder
Jlm
A fast LSTM Language Model for large vocabulary language like Japanese and Chinese
Stars: ✭ 105 (-11.76%)
Mutual labels:  decoder
Php Zxing
PHP wrapper for Zxing Java library
Stars: ✭ 93 (-21.85%)
Mutual labels:  decoder
Wx Voice
Convert audio files between Tencent apps (Weixin / Wechat, QQ) and Silk codec with other general formats such as MP3 and M4A
Stars: ✭ 93 (-21.85%)
Mutual labels:  decoder
Opusfile
Stand-alone decoder library for .opus streams
Stars: ✭ 86 (-27.73%)
Mutual labels:  decoder
Boswatch
Python Script to process input data from rtl_fm and multimon-NG - multiple Plugin support
Stars: ✭ 101 (-15.13%)
Mutual labels:  decoder
Vvdec
Fraunhofer Versatile Video Decoder (VVdeC)
Stars: ✭ 84 (-29.41%)
Mutual labels:  decoder
Sdp
RFC 4566 SDP implementation in go
Stars: ✭ 109 (-8.4%)
Mutual labels:  decoder
Decoder Plus Plus
An extensible application for penetration testers and software developers to decode/encode data into various formats.
Stars: ✭ 79 (-33.61%)
Mutual labels:  decoder
String Extra
Unicode/String support for Twig
Stars: ✭ 92 (-22.69%)
Mutual labels:  string
Strman Java
A Java 8 string manipulation library.
Stars: ✭ 1,362 (+1044.54%)
Mutual labels:  string
Analysis
A tool helping you to extract useful information from strings.
Stars: ✭ 118 (-0.84%)
Mutual labels:  string
Strtk
C++ String Toolkit Library
Stars: ✭ 113 (-5.04%)
Mutual labels:  string

HTMLString Swift 5.0 CocoaPods Carthage compatible Contact : @_alexaubry

HTMLString is a library written in Swift that allows your program to add and remove HTML entities in Strings.

Main features
πŸ” Adds entities for ASCII and UTF-8/UTF-16 encodings
πŸ“ Removes more than 2100 named entities (like &)
πŸ”’ Supports removing decimal and hexadecimal entities
🐣 Designed to support Swift Extended Grapheme Clusters (β†’ 100% emoji-proof)
βœ… Fully unit tested
⚑ Fast
πŸ“š Documented
πŸ€– Compatible with Objective-C

Supported Platforms

This package requires Swift 5 and Xcode 12.

  • iOS 9.0+
  • macOS 10.10+
  • tvOS 9.0+
  • watchOS 2.0+
  • Linux

Installation

Swift Package Manager

Add this line to your Package.swift :

.Package(url: "https://github.com/alexaubry/HTMLString", from: "6.0.0")

CocoaPods

Add this line to your Podfile:

pod 'HTMLString', '~> 6.0'

Carthage

Add this line to your Cartfile:

github "alexaubry/HTMLString" ~> 6.0

Usage

HTMLString allows you to add and remove HTML entities from a String.

πŸ” Adding HTML Entities (Escape)

When a character is not supported into the specified encoding, the library will replace it with a decimal entity (supported by all browsers supporting HTML 4 and later).

For instance, the & character will be replaced by &.

You can choose between ASCII and Unicode escaping:

  • Use the addingASCIIEntities function to escape for ASCII-encoded content
  • Use the addingUnicodeEntities function to escape for Unicode-compatible content

πŸ’‘ Pro Tip: When your content supports UTF-8 or UTF-16, use Unicode escaping as it is faster and produces a less bloated output.

Example

import HTMLString

let emoji = "My favorite emoji is πŸ™ƒ"
let escapedEmoji = emoji.addingASCIIEntities() // "My favorite emoji is 🙃"
let noNeedToEscapeThatEmoji = emoji.addingUnicodeEntities() // "My favorite emoji is πŸ™ƒ"

let snack = "Fish & Chips"
let escapedSnack = snack.addingASCIIEntities() // "Fish & Chips"
let weAlsoNeedToEscapeThisSnack = snack.addingUnicodeEntities() // "Fish & Chips"

πŸ“ Removing HTML Entities (Unescape)

To remove all the HTML entities from a String, use the removingHTMLEntities function.

Example

import HTMLString

let escapedEmoji = "My favorite emoji is 🙃"
let emoji = escapedEmoji.removingHTMLEntities() // "My favorite emoji is πŸ™ƒ"

let escapedSnack = "Fish & Chips"
let snack = escapedSnack.removingHTMLEntities() // "Fish & Chips"

Objective-C API

With Obj-C interoperability, you can import and use the HTMLString module from in Objective-C code.

The library introduces a set of Objective-C specific APIs as categories on the NSString type:

  • -[NSString stringByAddingUnicodeEntities]; : Replaces every character incompatible with HTML Unicode encoding by a decimal HTML entitiy.
  • -[NSString stringByAddingASCIIEntities]; : Replaces every character incompatible with HTML ASCII encoding by a decimal HTML entitiy.
  • -[NSString stringByRemovingHTMLEntities]; : Replaces every HTML entity with the matching Unicode character.

Escaping Examples

@import HTMLString;

NSString *emoji = @"My favorite emoji is πŸ™ƒ";
NSString *escapedEmoji = [emoji stringByAddingASCIIEntities]; // "My favorite emoji is 🙃"

NSString *snack = @"Fish & Chips";
NSString *escapedSnack = [snack stringByAddingUnicodeEntities]; // "Fish & Chips"

Unescaping Examples

@import HTMLString;

NSString *escapedEmoji = @"My favorite emoji is 🙃";
NSString *emoji = [escapedEmoji stringByRemovingHTMLEntities]; // "My favorite emoji is πŸ™ƒ"

NSString *escapedSnack = @"Fish & Chips";
NSString *snack = [escapedSnack stringByRemovingHTMLEntities]; // "Fish & Chips"

Author

License

HTMLString is available under the MIT license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].