Migrated OS X graphemes.m.

This commit is contained in:
Pietro Gagliardi 2018-03-04 15:48:45 -05:00
parent 7fd012418d
commit 36567cc522
3 changed files with 8 additions and 5 deletions

View File

@ -1,4 +1,5 @@
// 4 march 2018 // 4 march 2018
#import "../common/attrstr.h"
// opentype.m // opentype.m
extern CFArrayRef uiprivOpenTypeFeaturesToCTFeatures(const uiOpenTypeFeatures *otf); extern CFArrayRef uiprivOpenTypeFeaturesToCTFeatures(const uiOpenTypeFeatures *otf);

View File

@ -1,15 +1,16 @@
// 3 december 2016 // 3 december 2016
#import "uipriv_darwin.h" #import "uipriv_darwin.h"
#import "attrstr.h"
// CFStringGetRangeOfComposedCharactersAtIndex() is the function for grapheme clusters // CFStringGetRangeOfComposedCharactersAtIndex() is the function for grapheme clusters
// https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Strings/Articles/stringsClusters.html says that this does work on all multi-codepoint graphemes (despite the name), and that this is the preferred function for this particular job anyway // https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Strings/Articles/stringsClusters.html says that this does work on all multi-codepoint graphemes (despite the name), and that this is the preferred function for this particular job anyway
int graphemesTakesUTF16(void) int uiprivGraphemesTakesUTF16(void)
{ {
return 1; return 1;
} }
struct graphemes *graphemes(void *s, size_t len) struct graphemes *uiprivNewGraphemes(void *s, size_t len)
{ {
struct graphemes *g; struct graphemes *g;
UniChar *str = (UniChar *) s; UniChar *str = (UniChar *) s;
@ -18,7 +19,7 @@ struct graphemes *graphemes(void *s, size_t len)
CFRange range; CFRange range;
size_t i; size_t i;
g = uiNew(struct graphemes); g = uiprivNew(struct graphemes);
cfstr = CFStringCreateWithCharactersNoCopy(NULL, str, len, kCFAllocatorNull); cfstr = CFStringCreateWithCharactersNoCopy(NULL, str, len, kCFAllocatorNull);
if (cfstr == NULL) { if (cfstr == NULL) {
@ -34,8 +35,8 @@ struct graphemes *graphemes(void *s, size_t len)
ppos = range.location + range.length; ppos = range.location + range.length;
} }
g->pointsToGraphemes = (size_t *) uiAlloc((len + 1) * sizeof (size_t), "size_t[] (graphemes)"); g->pointsToGraphemes = (size_t *) uiprivAlloc((len + 1) * sizeof (size_t), "size_t[] (graphemes)");
g->graphemesToPoints = (size_t *) uiAlloc((g->len + 1) * sizeof (size_t), "size_t[] (graphemes)"); g->graphemesToPoints = (size_t *) uiprivAlloc((g->len + 1) * sizeof (size_t), "size_t[] (graphemes)");
// now calculate everything // now calculate everything
// fortunately due to the use of CFRange we can do this in one loop trivially! // fortunately due to the use of CFRange we can do this in one loop trivially!

View File

@ -1,5 +1,6 @@
// 11 may 2017 // 11 may 2017
#import "uipriv_darwin.h" #import "uipriv_darwin.h"
#import "attrstr.h"
struct addCTFeatureEntryParams { struct addCTFeatureEntryParams {
CFMutableArrayRef array; CFMutableArrayRef array;