<commit_before>---
layout: post
title: CFStringTransform

ref: "https://developer.apple.com/library/mac/documentation/CoreFOundation/Reference/CFMutableStringRef/Reference/reference.html#//apple_ref/doc/uid/20001504-CH201-BCIGCACA"
framework: Core Foundation
rating: 9.1

description: <tt>NSString</tt> is the crown jewel of Foundation. But as powerful as it is, we would be remiss no to mention its toll-free bridged cousin, <tt>CFMutableString</tt>. Or more specifically, <tt>CFStringTransform</tt>.
---

There are two indicators that can tell you pretty much everything you need to know about how nice a language is to use:

1. API Consistency
2. Quality of String Implementation

`NSString` is the crown jewel of Foundation. In an age where other languages _still_ struggle to handle Unicode correctly, `NSString` can not only handle anything you throw at it, but it can turn around and parse that input into linguistic tags. It's unfairly good.

But as powerful as `NSString` / `NSMutableString` are, we would be remiss not to mention their [toll-free bridged](http://developer.apple.com/library/ios/#documentation/CoreFoundation/Conceptual/CFDesignConcepts/Articles/tollFreeBridgedTypes.html) cousin, `CFMutableString`. Or more specifically, `CFStringTransform`.

As denoted by the `CF` prefix, `CFStringTransform` is part of Core Foundation, which is a C, rather than Objective-C API. The function returns a `Boolean` for whether or not the transform was successful, and takes the following arguments:

- `string`: The string to be transformed. Since this argument is a `CFMutableStringRef`, an `NSMutableString` can be passed using toll-free bridging.
- `range`: The range of the string over which the transformation should be applied.
- `transform`: The transformation to apply. This argument takes one of the string constants described below.
- `reverse`: Whether to run the transformation in reverse, where applicable.

`CFStringTransform` covers a lot of ground with its `transform` argument. Here's a rundown of what it can do:

## Strip Accents and Diacritics

Énġlišh långuãge lẳcks iñterêßţing diaçrïtičş, so it can be useful to normalize extended Latin characters into ASCII-friendly representations. You can get rid of the squiggly bits using the `kCFStringTransformStripCombiningMarks` transformation.

## Name Unicode Characters

`kCFStringTransformToUnicodeName` allows you to determine the Unicode standard name for special characters, including Emoji. For instance, "🐑💨✨" becomes "{SHEEP} {DASH SYMBOL} {SPARKLES}".
<commit_msg>Minor edit to CFStringTransform post<commit_after>---
layout: post
title: CFStringTransform

ref: "https://developer.apple.com/library/mac/documentation/CoreFOundation/Reference/CFMutableStringRef/Reference/reference.html#//apple_ref/doc/uid/20001504-CH201-BCIGCACA"
framework: CoreFoundation
rating: 9.1

description: <tt>NSString</tt> is the crown jewel of Foundation. But as powerful as it is, we would be remiss no to mention its toll-free bridged cousin, <tt>CFMutableString</tt>. Or more specifically, <tt>CFStringTransform</tt>.
---

There are two indicators that can tell you pretty much everything you need to know about how nice a language is to use:

1. API Consistency
2. Quality of String Implementation

`NSString` is the crown jewel of Foundation. In an age where other languages _still_ struggle to handle Unicode correctly, `NSString` can not only handle anything you throw at it, but it can turn around and parse that input into linguistic tags. It's unfairly good.

But as powerful as `NSString` / `NSMutableString` are, we would be remiss not to mention their [toll-free bridged](http://developer.apple.com/library/ios/#documentation/CoreFoundation/Conceptual/CFDesignConcepts/Articles/tollFreeBridgedTypes.html) cousin, `CFMutableString`. Or more specifically, `CFStringTransform`.

As denoted by the `CF` prefix, `CFStringTransform` is part of Core Foundation, which is a C, rather than Objective-C API. The function returns a `Boolean` for whether or not the transform was successful, and takes the following arguments:

- `string`: The string to be transformed. Since this argument is a `CFMutableStringRef`, an `NSMutableString` can be passed using toll-free bridging.
- `range`: The range of the string over which the transformation should be applied.
- `transform`: The transformation to apply. This argument takes one of the string constants described below.
- `reverse`: Whether to run the transformation in reverse, where applicable.

`CFStringTransform` covers a lot of ground with its `transform` argument. Here's a rundown of what it can do:

## Strip Accents and Diacritics

Énġlišh långuãge lẳcks iñterêßţing diaçrïtičş, so it can be useful to normalize extended Latin characters into ASCII-friendly representations. You can get rid of the squiggly bits using the `kCFStringTransformStripCombiningMarks` transformation.

## Name Unicode Characters

`kCFStringTransformToUnicodeName` allows you to determine the Unicode standard name for special characters, including Emoji. For instance, "🐑💨✨" becomes "{SHEEP} {DASH SYMBOL} {SPARKLES}".

{'fraction_non_alphanumeric': 0.07298985167837627, 'fraction_numerical': 0.00585480093676815, 'mean_word_length': 5.234793187347932, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3816474', 'n_tokens_mistral': 1446, 'n_tokens_neox': 1359, 'n_words': 629}