Latest 0.2.0
Homepage https://github.com/bnickel/SEStringUtilities
License MIT
Platforms ios 5.0, osx 10.7, requires ARC
Frameworks Foundation
Authors

SEStringUtilities provide a handful of useful string functions used in Stack Exchange.app.

NSAttributedString+SETokenReplacement

Categories on NSString and NSAttributedString that allow you to do string templating in a clear and localizable way. Similar to Mustache but for small strings and with attributed string support:

NSAttributedString *username = ...;
NSString *creationDate = ...;
label.attributedText =
    [NSLocalizedString(@"- Asked by {username} on {creationDate}", nil)
     SE_attributedStringByReplacingTokensWithValues:NSDictionaryOfVariableBindings(username, creationDate)];
let username:NSAttributedString = ...
let creationDate:String = ...
label.attributedText =
    NSLocalizedString("- Asked by {username} on {creationDate}", comment:"").
    SE_attributedStringByReplacingTokensWithValues({"username": username, "creationDate": creationDate})

In these examples username is an attributed string using its own styling and creationDate is a string inheriting its styling from the parent attributed string.

NSString+SERegularExpressions

A category on NSString providing functionality similar to JavaScript’s String.prototype.replace.

-[NSString SE_stringByReplacingPattern:options:withTemplate:] is similar to -[NSRegularExpression stringByReplacingMatchesInString:options:range:withTemplate:] but a little terser since it takes ownership of creating the regular expression and assumes some default values.

-[NSString SE_stringByReplacingPattern:options:withBlock:] on the other hand adds new functionality in that you can easily provide your own complex transformations for the contents of the block. SEMarkdownEditor uses this for complex operations including this gnarly recursive transform.

Both methods have a ReplacingFirstOccuranceOfPattern variant which limits the change to the first match.

Installation

pod 'SEStringUtilities'

Latest podspec

{
    "name": "SEStringUtilities",
    "version": "0.2.0",
    "summary": "A few simple string replacement utilities.",
    "homepage": "https://github.com/bnickel/SEStringUtilities",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Brian Nickel": "[email protected]"
    },
    "source": {
        "git": "https://github.com/bnickel/SEStringUtilities.git",
        "tag": "v0.2.0"
    },
    "source_files": "SEStringUtilities",
    "public_header_files": "SEStringUtilities/**/*.h",
    "frameworks": "Foundation",
    "requires_arc": true,
    "platforms": {
        "ios": "5.0",
        "osx": "10.7"
    }
}

Pin It on Pinterest

Share This