From 36567cc52235781a31f5ab3767b241c8d9e545e7 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 4 Mar 2018 15:48:45 -0500 Subject: [PATCH] Migrated OS X graphemes.m. --- darwin/attrstr.h | 1 + darwin/{OLD_graphemes.m => graphemes.m} | 11 ++++++----- darwin/opentype.m | 1 + 3 files changed, 8 insertions(+), 5 deletions(-) rename darwin/{OLD_graphemes.m => graphemes.m} (79%) diff --git a/darwin/attrstr.h b/darwin/attrstr.h index 8221b8b4..537243bb 100644 --- a/darwin/attrstr.h +++ b/darwin/attrstr.h @@ -1,4 +1,5 @@ // 4 march 2018 +#import "../common/attrstr.h" // opentype.m extern CFArrayRef uiprivOpenTypeFeaturesToCTFeatures(const uiOpenTypeFeatures *otf); diff --git a/darwin/OLD_graphemes.m b/darwin/graphemes.m similarity index 79% rename from darwin/OLD_graphemes.m rename to darwin/graphemes.m index e5ee816f..3fdbc17e 100644 --- a/darwin/OLD_graphemes.m +++ b/darwin/graphemes.m @@ -1,15 +1,16 @@ // 3 december 2016 #import "uipriv_darwin.h" +#import "attrstr.h" // 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 -int graphemesTakesUTF16(void) +int uiprivGraphemesTakesUTF16(void) { return 1; } -struct graphemes *graphemes(void *s, size_t len) +struct graphemes *uiprivNewGraphemes(void *s, size_t len) { struct graphemes *g; UniChar *str = (UniChar *) s; @@ -18,7 +19,7 @@ struct graphemes *graphemes(void *s, size_t len) CFRange range; size_t i; - g = uiNew(struct graphemes); + g = uiprivNew(struct graphemes); cfstr = CFStringCreateWithCharactersNoCopy(NULL, str, len, kCFAllocatorNull); if (cfstr == NULL) { @@ -34,8 +35,8 @@ struct graphemes *graphemes(void *s, size_t len) ppos = range.location + range.length; } - g->pointsToGraphemes = (size_t *) uiAlloc((len + 1) * sizeof (size_t), "size_t[] (graphemes)"); - g->graphemesToPoints = (size_t *) uiAlloc((g->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 *) uiprivAlloc((g->len + 1) * sizeof (size_t), "size_t[] (graphemes)"); // now calculate everything // fortunately due to the use of CFRange we can do this in one loop trivially! diff --git a/darwin/opentype.m b/darwin/opentype.m index 0b2647e9..de4bb093 100644 --- a/darwin/opentype.m +++ b/darwin/opentype.m @@ -1,5 +1,6 @@ // 11 may 2017 #import "uipriv_darwin.h" +#import "attrstr.h" struct addCTFeatureEntryParams { CFMutableArrayRef array;