From fecb443838c28ba0665208f74efabe6b327b7252 Mon Sep 17 00:00:00 2001 From: loccun Date: Tue, 14 Apr 2026 06:23:22 +0700 Subject: [PATCH 1/5] feat: implement 3-state W2U toggle --- bamboo.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/bamboo.go b/bamboo.go index d873abf..cd4e199 100644 --- a/bamboo.go +++ b/bamboo.go @@ -45,6 +45,7 @@ type IEngine interface { SetFlag(uint) GetInputMethod() InputMethod ProcessKey(rune, Mode) + SetW2UMode(int) ProcessString(string, Mode) GetProcessedString(Mode) string IsValid(bool) bool @@ -59,6 +60,7 @@ type BambooEngine struct { composition []*Transformation inputMethod InputMethod flags uint + w2uMode int // 0: Disabled, 1: Middle-Only, 2: Everywhere } func NewEngine(inputMethod InputMethod, flag uint) IEngine { @@ -77,6 +79,10 @@ func (e *BambooEngine) SetFlag(flag uint) { e.flags = flag } +func (e *BambooEngine) SetW2UMode(mode int) { + e.w2uMode = mode +} + func (e *BambooEngine) GetFlag(flag uint) uint { return e.flags } @@ -123,7 +129,18 @@ func (e *BambooEngine) generateTransformations(composition []*Transformation, lo // If none of the applicable_rules can actually be applied then this new // transformation fall-backs to an APPENDING one. transformations = generateFallbackTransformations(composition, e.getApplicableRules(lowerKey), lowerKey, isUpperCase) - if e.flags&Ew2uEnabled != 0 && lowerKey == 'w' && len(transformations) > 0 { + + // Unified Modular W2U Logic + canApplyW2U := false + if e.w2uMode == 1 { + if len(composition) > 0 { + canApplyW2U = true + } + } else if e.w2uMode == 2 { + canApplyW2U = true + } + + if canApplyW2U && lowerKey == 'w' && len(transformations) > 0 { if transformations[0].Rule.Result == 'w' { transformations[0].Rule.Result = 'ư' transformations[0].Rule.EffectOn = 'ư' From e38fd91cf9358cf3b262f3e10046c4b90c007b30 Mon Sep 17 00:00:00 2001 From: loccun Date: Tue, 14 Apr 2026 06:27:43 +0700 Subject: [PATCH 2/5] fix: implement safe sentinel for W2U modular logic --- bamboo.go | 9 ++++++--- final_race_test_output.txt | 1 + race_test_output.txt | 5 +++++ 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 final_race_test_output.txt create mode 100644 race_test_output.txt diff --git a/bamboo.go b/bamboo.go index cd4e199..3895c68 100644 --- a/bamboo.go +++ b/bamboo.go @@ -60,13 +60,14 @@ type BambooEngine struct { composition []*Transformation inputMethod InputMethod flags uint - w2uMode int // 0: Disabled, 1: Middle-Only, 2: Everywhere + w2uMode int // -1: Follow flags, 0: Disabled, 1: Middle-Only, 2: Everywhere } func NewEngine(inputMethod InputMethod, flag uint) IEngine { engine := BambooEngine{ inputMethod: inputMethod, flags: flag, + w2uMode: -1, } return &engine } @@ -131,8 +132,10 @@ func (e *BambooEngine) generateTransformations(composition []*Transformation, lo transformations = generateFallbackTransformations(composition, e.getApplicableRules(lowerKey), lowerKey, isUpperCase) // Unified Modular W2U Logic - canApplyW2U := false - if e.w2uMode == 1 { + var canApplyW2U bool + if e.w2uMode == -1 { + canApplyW2U = e.flags&Ew2uEnabled != 0 + } else if e.w2uMode == 1 { if len(composition) > 0 { canApplyW2U = true } diff --git a/final_race_test_output.txt b/final_race_test_output.txt new file mode 100644 index 0000000..1c538a9 --- /dev/null +++ b/final_race_test_output.txt @@ -0,0 +1 @@ +ok github.com/BambooEngine/bamboo-core 1.216s diff --git a/race_test_output.txt b/race_test_output.txt new file mode 100644 index 0000000..04698c4 --- /dev/null +++ b/race_test_output.txt @@ -0,0 +1,5 @@ +--- FAIL: TestEw2uEnabled (0.00s) + bamboo_test.go:656: Ew2uEnabled OFF: Process [w], got [ư] expected [w] +FAIL +FAIL github.com/BambooEngine/bamboo-core 0.215s +FAIL From 2794b34a27036e4044580d1e90ab95fda5b9b3e9 Mon Sep 17 00:00:00 2001 From: loccun Date: Tue, 14 Apr 2026 06:28:35 +0700 Subject: [PATCH 3/5] chore: remove accidental test log files --- final_race_test_output.txt | 1 - race_test_output.txt | 5 ----- 2 files changed, 6 deletions(-) delete mode 100644 final_race_test_output.txt delete mode 100644 race_test_output.txt diff --git a/final_race_test_output.txt b/final_race_test_output.txt deleted file mode 100644 index 1c538a9..0000000 --- a/final_race_test_output.txt +++ /dev/null @@ -1 +0,0 @@ -ok github.com/BambooEngine/bamboo-core 1.216s diff --git a/race_test_output.txt b/race_test_output.txt deleted file mode 100644 index 04698c4..0000000 --- a/race_test_output.txt +++ /dev/null @@ -1,5 +0,0 @@ ---- FAIL: TestEw2uEnabled (0.00s) - bamboo_test.go:656: Ew2uEnabled OFF: Process [w], got [ư] expected [w] -FAIL -FAIL github.com/BambooEngine/bamboo-core 0.215s -FAIL From 8f7f7fcdd2a9b939902f77f3f54cc70763431ead Mon Sep 17 00:00:00 2001 From: loccun Date: Tue, 14 Apr 2026 06:30:55 +0700 Subject: [PATCH 4/5] refactor: define W2U constants and simplify logic per PR feedback --- bamboo.go | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/bamboo.go b/bamboo.go index 3895c68..66b41aa 100644 --- a/bamboo.go +++ b/bamboo.go @@ -26,6 +26,13 @@ const ( InReverseOrder ) +const ( + W2uFollowFlags = -1 + W2uDisabled = 0 + W2uMiddleOnly = 1 + W2uEverywhere = 2 +) + const ( EfreeToneMarking uint = 1 << iota EstdToneStyle @@ -60,14 +67,14 @@ type BambooEngine struct { composition []*Transformation inputMethod InputMethod flags uint - w2uMode int // -1: Follow flags, 0: Disabled, 1: Middle-Only, 2: Everywhere + w2uMode int // W2uFollowFlags, W2uDisabled, W2uMiddleOnly, W2uEverywhere } func NewEngine(inputMethod InputMethod, flag uint) IEngine { engine := BambooEngine{ inputMethod: inputMethod, flags: flag, - w2uMode: -1, + w2uMode: W2uFollowFlags, } return &engine } @@ -81,7 +88,9 @@ func (e *BambooEngine) SetFlag(flag uint) { } func (e *BambooEngine) SetW2UMode(mode int) { - e.w2uMode = mode + if mode >= W2uDisabled && mode <= W2uEverywhere { + e.w2uMode = mode + } } func (e *BambooEngine) GetFlag(flag uint) uint { @@ -132,16 +141,9 @@ func (e *BambooEngine) generateTransformations(composition []*Transformation, lo transformations = generateFallbackTransformations(composition, e.getApplicableRules(lowerKey), lowerKey, isUpperCase) // Unified Modular W2U Logic - var canApplyW2U bool - if e.w2uMode == -1 { - canApplyW2U = e.flags&Ew2uEnabled != 0 - } else if e.w2uMode == 1 { - if len(composition) > 0 { - canApplyW2U = true - } - } else if e.w2uMode == 2 { - canApplyW2U = true - } + canApplyW2U := (e.w2uMode == W2uEverywhere) || + (e.w2uMode == W2uMiddleOnly && len(composition) > 0) || + (e.w2uMode == W2uFollowFlags && e.flags&Ew2uEnabled != 0) if canApplyW2U && lowerKey == 'w' && len(transformations) > 0 { if transformations[0].Rule.Result == 'w' { From 0698dec5521fa08985b0fa3aa73b82e62e284231 Mon Sep 17 00:00:00 2001 From: loccun Date: Tue, 14 Apr 2026 06:44:02 +0700 Subject: [PATCH 5/5] refactor: rename Middle-Only to Non-Start for precision --- bamboo.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bamboo.go b/bamboo.go index 66b41aa..8d2b77f 100644 --- a/bamboo.go +++ b/bamboo.go @@ -29,7 +29,7 @@ const ( const ( W2uFollowFlags = -1 W2uDisabled = 0 - W2uMiddleOnly = 1 + W2uNonStart = 1 W2uEverywhere = 2 ) @@ -67,7 +67,7 @@ type BambooEngine struct { composition []*Transformation inputMethod InputMethod flags uint - w2uMode int // W2uFollowFlags, W2uDisabled, W2uMiddleOnly, W2uEverywhere + w2uMode int // W2uFollowFlags, W2uDisabled, W2uNonStart, W2uEverywhere } func NewEngine(inputMethod InputMethod, flag uint) IEngine { @@ -142,7 +142,7 @@ func (e *BambooEngine) generateTransformations(composition []*Transformation, lo // Unified Modular W2U Logic canApplyW2U := (e.w2uMode == W2uEverywhere) || - (e.w2uMode == W2uMiddleOnly && len(composition) > 0) || + (e.w2uMode == W2uNonStart && len(composition) > 0) || (e.w2uMode == W2uFollowFlags && e.flags&Ew2uEnabled != 0) if canApplyW2U && lowerKey == 'w' && len(transformations) > 0 {