//C++ TO C# CONVERTER WARNING: 'const' methods are not available in C#: //ORIGINAL LINE: const Trie* trieTable() const public Trie trieTable() { //C++ TO C# CONVERTER TODO TASK: There is no equivalent to 'reinterpret_cast' in C#: return(reinterpret_cast <const Trie>(bytes() + trie_offset)); }
// calculate hyphenation from patterns, assuming alphabet lookup has already // been done /** * Internal implementation, after conversion to codes. All case folding and * normalization has been done by now, and all characters have been found in the * alphabet. Note: len here is the padded length including 0 codes at start and * end. **/ private void hyphenateFromCodes(HyphenationType[] result, UInt16[] codes, int len, HyphenationType hyphenValue) { //C++ TO C# CONVERTER TODO TASK: There is no equivalent in C# to 'static_assert': // static_assert(sizeof(HyphenationType) == sizeof(byte), "HyphnationType must be byte."); // Reuse the result array as a buffer for calculating intermediate hyphenation // numbers. //C++ TO C# CONVERTER TODO TASK: There is no equivalent to 'reinterpret_cast' in C#: byte[] buffer = reinterpret_cast <byte>(result); Header header = getHeader(); Trie trie = header.trieTable(); Pattern pattern = header.patternTable(); uint char_mask = new uint(trie.char_mask); uint link_shift = new uint(trie.link_shift); uint link_mask = new uint(trie.link_mask); uint pattern_shift = new uint(trie.pattern_shift); int maxOffset = len - minSuffix - 1; for (int i = 0; i < len - 1; i++) { uint node = 0; // index into Trie table for (int j = i; j < len; j++) { UInt16 c = codes[j]; uint entry = trie.data[node + c]; if ((entry & char_mask) == c) { node = (entry & link_mask) >> link_shift; } else { break; } uint pat_ix = trie.data[node] >> pattern_shift; // pat_ix contains a 3-tuple of length, shift (number of trailing zeros), // and an offset into the buf pool. This is the pattern for the substring // (i..j) we just matched, which we combine (via point-wise max) into the // buffer vector. if (pat_ix != 0) { uint pat_entry = pattern.data[pat_ix]; int pat_len = Pattern.len(new uint(pat_entry)); int pat_shift = Pattern.shift(new uint(pat_entry)); byte[] pat_buf = pattern.buf(new uint(pat_entry)); int offset = j + 1 - (pat_len + pat_shift); // offset is the index within buffer that lines up with the start of // pat_buf int start = Math.Max((int)minPrefix - offset, 0); int end = Math.Min(pat_len, (int)maxOffset - offset); for (int k = start; k < end; k++) { buffer[offset + k] = Math.Max(buffer[offset + k], pat_buf[k]); } } } } // Since the above calculation does not modify values outside // [minPrefix, len - minSuffix], they are left as 0 = DONT_BREAK. for (int i = minPrefix; i < maxOffset; i++) { // Hyphenation opportunities happen when the hyphenation numbers are odd. result[i] = ((buffer[i] & 1u) != null) ? hyphenValue : HyphenationType.DONT_BREAK; } }