Files
swift-mirror/stdlib/runtime/UnicodeExtendedGraphemeClusters.cpp.gyb
Dmitri Hrybenko 4814e00fda stdlib/String: implement Unicode extended grapheme cluster segmentation
algorithm

The implementation uses a specialized trie that has not been tuned to the table
data.  I tried guessing parameter values that should work well, but did not do
any performance measurements.

There is no efficient way to initialize arrays with static data in Swift.  The
required tables are being generated as C++ code in the runtime library.

rdar://16013860


Swift SVN r19340
2014-06-30 14:38:53 +00:00

134 lines
4.3 KiB
Swift

%# -*- mode: swift -*-
%# Ignore the following admonition; it applies to the resulting .cpp file only
//// Automatically Generated From UnicodeExtendedGraphemeClusters.cpp.gyb.
//// Do Not Edit Directly!
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
%{
# FIXME: this table should be moved to a Swift file in stdlib. Unfortunately,
# in Swift we don't have a way to statically initialize arrays.
from GYBUnicodeDataUtils import *
grapheme_cluster_break_property_table = \
GraphemeClusterBreakPropertyTable(unicodeGraphemeBreakPropertyFile)
trie_generator = UnicodeTrieGenerator()
trie_generator.fill_from_unicode_property(grapheme_cluster_break_property_table)
trie_generator.verify(grapheme_cluster_break_property_table)
}%
/// Before compression:
/// BMP_lookup: ${len(trie_generator.BMP_lookup)}
/// BMP_data: ${len(trie_generator.BMP_data)} x ${len(trie_generator.BMP_data[0])}
/// supp_lookup1: ${len(trie_generator.supp_lookup1)}
/// supp_lookup2: ${len(trie_generator.supp_lookup2)} x ${len(trie_generator.supp_lookup2[0])}
/// supp_data: ${len(trie_generator.supp_data)} x ${len(trie_generator.supp_data[0])}
%{
trie_generator.freeze()
trie_generator.verify(grapheme_cluster_break_property_table)
}%
/// After compression:
/// BMP_lookup: ${len(trie_generator.BMP_lookup)}
/// BMP_data: ${len(trie_generator.BMP_data)} x ${len(trie_generator.BMP_data[0])}
/// supp_lookup1: ${len(trie_generator.supp_lookup1)}
/// supp_lookup2: ${len(trie_generator.supp_lookup2)} x ${len(trie_generator.supp_lookup2[0])}
/// supp_data: ${len(trie_generator.supp_data)} x ${len(trie_generator.supp_data[0])}
%{
trie_generator.serialize(grapheme_cluster_break_property_table)
}%
#include <stdint.h>
const uint8_t _swift_stdlib_GraphemeClusterBreakPropertyTrieImpl[] = {
% for byte in trie_generator.trie_bytes:
${byte},
% end
};
extern "C"
const uint8_t *_swift_stdlib_GraphemeClusterBreakPropertyTrie =
_swift_stdlib_GraphemeClusterBreakPropertyTrieImpl;
struct _swift_stdlib_GraphemeClusterBreakPropertyTrieMetadataTy {
unsigned BMPFirstLevelIndexBits;
unsigned BMPDataOffsetBits;
unsigned SuppFirstLevelIndexBits;
unsigned SuppSecondLevelIndexBits;
unsigned SuppDataOffsetBits;
unsigned BMPLookupBytesPerEntry;
unsigned BMPDataBytesPerEntry;
unsigned SuppLookup1BytesPerEntry;
unsigned SuppLookup2BytesPerEntry;
unsigned SuppDataBytesPerEntry;
unsigned TrieSize;
unsigned BMPLookupBytesOffset;
unsigned BMPDataBytesOffset;
unsigned SuppLookup1BytesOffset;
unsigned SuppLookup2BytesOffset;
unsigned SuppDataBytesOffset;
};
extern "C" const struct _swift_stdlib_GraphemeClusterBreakPropertyTrieMetadataTy
_swift_stdlib_GraphemeClusterBreakPropertyTrieMetadata = {
${trie_generator.BMP_first_level_index_bits},
${trie_generator.BMP_data_offset_bits},
${trie_generator.supp_first_level_index_bits},
${trie_generator.supp_second_level_index_bits},
${trie_generator.supp_data_offset_bits},
${trie_generator.BMP_lookup_bytes_per_entry},
${trie_generator.BMP_data_bytes_per_entry},
${trie_generator.supp_lookup1_bytes_per_entry},
${trie_generator.supp_lookup2_bytes_per_entry},
${trie_generator.supp_data_bytes_per_entry},
${len(trie_generator.trie_bytes)},
${trie_generator.BMP_lookup_bytes_offset},
${trie_generator.BMP_data_bytes_offset},
${trie_generator.supp_lookup1_bytes_offset},
${trie_generator.supp_lookup2_bytes_offset},
${trie_generator.supp_data_bytes_offset},
};
%{
extended_grapheme_cluster_rules_matrix = \
get_extended_grapheme_cluster_rules_matrix(grapheme_cluster_break_property_table)
}%
const uint16_t _swift_stdlib_ExtendedGraphemeClusterNoBoundaryRulesMatrixImpl[] = {
% for row in get_extended_grapheme_cluster_rules_matrix(grapheme_cluster_break_property_table):
${row},
% end
};
const uint16_t *_swift_stdlib_ExtendedGraphemeClusterNoBoundaryRulesMatrix =
_swift_stdlib_ExtendedGraphemeClusterNoBoundaryRulesMatrixImpl;