You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file provides guidance to AI agents when working with code in this repository.
4
+
5
+
## Build Commands
6
+
7
+
```bash
8
+
dotnet restore # Restore dependencies
9
+
dotnet build --no-restore # Build solution
10
+
dotnet test --no-build # Run tests
11
+
dotnet test --verbosity normal # Run tests with detailed output
12
+
```
13
+
14
+
The solution targets .NET Standard 2.0 (library) and .NET 8.0 (tests). Tests use MSTest framework.
15
+
16
+
## Architecture Overview
17
+
18
+
UnicodeHelper is a .NET library that provides Unicode property access and enhanced string handling for characters beyond the Basic Multilingual Plane (codepoints > U+FFFF). It supports Unicode 17.0.0.
19
+
20
+
### Core Types
21
+
22
+
**UCodepoint** (`UnicodeHelper/UCodepoint.cs`) - Readonly struct representing a single Unicode codepoint (0x0000-0x10FFFF). Primary API for querying Unicode properties. Implicitly converts from `char` for BMP characters.
23
+
24
+
**UString** (`UnicodeHelper/UString.cs`) - Sealed class representing a sequence of Unicode codepoints. Unlike .NET strings, treats upper-plane characters (emoji, etc.) as single units rather than surrogate pairs. Work-in-progress; not all methods fully implemented.
25
+
26
+
**UStringBuilder** (`UnicodeHelper/UStringBuilder.cs`) - Efficient builder for constructing UStrings. Uses ArrayPool for buffer management; must be disposed.
-**HelperUtils** - Text direction algorithm implementation
48
+
49
+
### Embedded Resources
50
+
51
+
All Unicode data files are embedded in `UnicodeHelper/Resources/Resources.zip` for offline use. Data is loaded lazily on first access via static constructors.
52
+
53
+
## Testing Approach
54
+
55
+
Every implemented method should be extensively tested. Tests compare behavior against .NET's built-in Unicode support where applicable. The `UnicodeHelper.Tests/TestData/NormalizationTest.txt` contains normalization test cases. Data-driven tests use `[DynamicData]` attributes.
This file provides guidance to AI agents when working with code in this repository.
4
+
5
+
## Module Purpose
6
+
7
+
This is the core library implementing Unicode property access and codepoint-aware string handling. It abstracts away .NET's UTF-16 surrogate pair complexity by treating all Unicode codepoints (including upper-plane characters like emoji) as single units.
8
+
9
+
## Architectural Decisions
10
+
11
+
### Data Storage Strategy
12
+
Unicode property data uses large arrays indexed directly by codepoint value (0-0x10FFFF = 1,114,112 entries). This trades memory for O(1) lookup performance:
13
+
-`UnicodeData.categories[]` - byte array for UnicodeCategory
14
+
-`UnicodeData.bidiClasses[]` - enum array for bidirectional class
- Dictionary lookups only for sparse data (numeric values, case mappings, decomposition mappings)
17
+
18
+
### Lazy Initialization Pattern
19
+
All static data classes (`UnicodeData`, `UnicodeProperties`, `UnicodeNames`, `UnicodeBlocks`) use static constructors that load from embedded resources on first access. Each provides an empty `Init()` method to allow explicit initialization timing (e.g., during splash screen).
20
+
21
+
### Substring Sharing
22
+
`UString` instances share their backing `UCodepoint[]` array. Substrings store `_startIndex` and `Length` offsets into the parent array rather than copying. This makes substring operations O(1) but means the parent array stays in memory as long as any substring exists.
23
+
24
+
### Memory Pooling
25
+
`UStringBuilder` uses `ArrayPool<UCodepoint>.Shared` for buffer management. **Must be disposed** to return buffers to the pool. The finalizer also returns the buffer, but relying on it is inefficient.
26
+
27
+
## Design Patterns
28
+
29
+
### Facade Pattern
30
+
`UCodepoint` acts as a facade for Unicode property lookups. Static methods like `GetUnicodeCategory()`, `IsWhiteSpace()`, `ToUpper()` delegate to `UnicodeData` or `UnicodeProperties` internally.
31
+
32
+
### Value Type Wrapper
33
+
`UCodepoint` is a readonly struct wrapping a single `int _value`. Provides implicit conversion from `char` (for BMP characters) and explicit conversions to/from `int`. Operator overloads allow direct comparison with integers and chars.
34
+
35
+
### Internal Namespace Separation
36
+
`UnicodeHelper.Internal` contains implementation helpers not part of the public API:
37
+
-`DataHelper` - Resource loading and CSV parsing configuration
38
+
-`NormalizationEngine` - Unicode normalization (ported from W3C reference)
39
+
-`HelperUtils` - Canonical sorting, text direction algorithm
40
+
-`UnicodeConversion` - String-to-enum conversions for Unicode data files
41
+
42
+
## Key Implementation Details
43
+
44
+
### Unicode Data File Format
45
+
Uses CsvHelper with semicolon delimiter (`Delimiter = ";"`) to parse Unicode Consortium data files. Comment character is `#`. Configuration in `DataHelper.CsvConfiguration`.
46
+
47
+
### Normalization Implementation
48
+
`NormalizationEngine` is ported from the W3C reference implementation. Handles Hangul syllable decomposition/composition separately using algorithmic approach (constants `SBase`, `LBase`, `VBase`, `TBase`). Decomposition mappings are pre-expanded fully during initialization.
49
+
50
+
### Bidi Default Values
51
+
`UnicodeData.Init()` sets default bidirectional classes by range before loading actual data. Ranges follow DerivedBidiClass.txt specification (e.g., 0x0590-0x05FF defaults to RightToLeft).
52
+
53
+
### Combining Key Encoding
54
+
Composition/decomposition lookups use packed keys:
55
+
- Decomposition: `(compatMapping << 21) | codepoint` as `int`
0 commit comments