Permalink
Browse files

Implementing diff_rangesToCharsMungeCFStringCreate().

  • Loading branch information...
1 parent aae0bfe commit b99ce5a3aa33bf8dd9d89b790a6faab2e2212eac @JanX2 committed Sep 5, 2012
Showing with 25 additions and 0 deletions.
  1. +24 −0 DiffMatchPatchCFUtilities.c
  2. +1 −0 DiffMatchPatchCFUtilities.h
@@ -504,6 +504,30 @@ CFStringRef diff_tokensToCharsMungeCFStringCreate(CFStringRef text, CFMutableArr
}
/**
+ * Split a text into a list of strings. Reduce the texts to a CFStringRef of
+ * hashes where where each Unicode character represents the substring for a CFRange.
+ * @param text CFString to encode.
+ * @param substringArray CFMutableArray of unique strings.
+ * @param substringHash Map of strings to indices.
+ * @param ranges C array of CFRange structs determining the subranges to hash.
+ * @param ranges_count Count of the CFRange structs contained in ranges.
+ * @return Encoded CFStringRef.
+ */
+CFStringRef diff_rangesToCharsMungeCFStringCreate(CFStringRef text, CFMutableArrayRef substringArray, CFMutableDictionaryRef substringHash, CFRange *ranges, size_t ranges_count) {
+
+ CFMutableStringRef chars = CFStringCreateMutable(kCFAllocatorDefault, 0);
+
+ for (size_t i = 0; i < ranges_count; i++) {
+ CFRange substringRange = ranges[i];
+
+ diff_mungeTokenForRange(text, substringRange, chars, substringHash, substringArray);
+ }
+
+ return chars;
+
+}
+
+/**
* Split a text into a list of strings. Reduce the texts to a CFStringRef of
* hashes where where each Unicode character represents one word (or boundary between words).
* @param text CFString to encode.
@@ -64,6 +64,7 @@ CFStringRef diff_wordsToCharsMungeCFStringCreate(CFStringRef text, CFMutableArra
CFStringRef diff_sentencesToCharsMungeCFStringCreate(CFStringRef text, CFMutableArrayRef tokenArray, CFMutableDictionaryRef tokenHash);
CFStringRef diff_paragraphsToCharsMungeCFStringCreate(CFStringRef text, CFMutableArrayRef tokenArray, CFMutableDictionaryRef tokenHash);
CFStringRef diff_lineBreakDelimiteredToCharsMungeCFStringCreate(CFStringRef text, CFMutableArrayRef tokenArray, CFMutableDictionaryRef tokenHash);
+CFStringRef diff_rangesToCharsMungeCFStringCreate(CFStringRef text, CFMutableArrayRef substringArray, CFMutableDictionaryRef substringHash, CFRange *ranges, size_t ranges_count);
CFStringRef diff_charsToTokenCFStringCreate(CFStringRef charsString, CFArrayRef tokenArray);

0 comments on commit b99ce5a

Please sign in to comment.