[PATCH 1/2] WINGs: make UTF-8 functions global

0 views
Skip to first unread message

david.m...@gmail.com

unread,
Apr 4, 2026, 2:33:52 PM (2 days ago) Apr 4
to Window Maker Development
This patch is moving the existing UTF-8 functions from wtextfield.c
to WINGsP.h.in to be available to all modules.
---
 WINGs/WINGs/WINGsP.h.in | 31 +++++++++++++++++++++++++++++++
 WINGs/wtextfield.c      | 29 -----------------------------
 2 files changed, 31 insertions(+), 29 deletions(-)

diff --git a/WINGs/WINGs/WINGsP.h.in b/WINGs/WINGs/WINGsP.h.in
index 2c36b269..02d288f3 100644
--- a/WINGs/WINGs/WINGsP.h.in
+++ b/WINGs/WINGs/WINGsP.h.in
@@ -686,6 +686,37 @@ void W_BroadcastMessage(W_View *targetParent, XEvent *event);
 
 void W_DispatchMessage(W_View *target, XEvent *event);
 
+/* ---[ UTF-8 helpers ]--------------------------------------------------- */
+
+static inline int oneUTF8CharBackward(const char *str, int len)
+{
+ const unsigned char *ustr = (const unsigned char *)str;
+ int pos = 0;
+
+ while (len-- > 0 && ustr[--pos] >= 0x80 && ustr[pos] <= 0xbf) ;
+ return pos;
+}
+
+static inline int oneUTF8CharForward(const char *str, int len)
+{
+ const unsigned char *ustr = (const unsigned char *)str;
+ int pos = 0;
+
+ while (len-- > 0 && ustr[++pos] >= 0x80 && ustr[pos] <= 0xbf) ;
+ return pos;
+}
+
+// find the beginning of the UTF8 char pointed by str
+static inline int seekUTF8CharStart(const char *str, int len)
+{
+ const unsigned char *ustr = (const unsigned char *)str;
+ int pos = 0;
+
+ while (len-- > 0 && ustr[pos] >= 0x80 && ustr[pos] <= 0xbf)
+ --pos;
+ return pos;
+}
+
 
 #ifdef __cplusplus
 }
diff --git a/WINGs/wtextfield.c b/WINGs/wtextfield.c
index 52b577e5..4d25a3e5 100644
--- a/WINGs/wtextfield.c
+++ b/WINGs/wtextfield.c
@@ -122,35 +122,6 @@ static WMSelectionProcs selectionHandler = {
 #define TEXT_WIDTH2(tPtr, start, end) (WMWidthOfString((tPtr)->font, \
     &((tPtr)->text[(start)]), (end) - (start)))
 
-static inline int oneUTF8CharBackward(const char *str, int len)
-{
- const unsigned char *ustr = (const unsigned char *)str;
- int pos = 0;
-
- while (len-- > 0 && ustr[--pos] >= 0x80 && ustr[pos] <= 0xbf) ;
- return pos;
-}
-
-static inline int oneUTF8CharForward(const char *str, int len)
-{
- const unsigned char *ustr = (const unsigned char *)str;
- int pos = 0;
-
- while (len-- > 0 && ustr[++pos] >= 0x80 && ustr[pos] <= 0xbf) ;
- return pos;
-}
-
-// find the beginning of the UTF8 char pointed by str
-static inline int seekUTF8CharStart(const char *str, int len)
-{
- const unsigned char *ustr = (const unsigned char *)str;
- int pos = 0;
-
- while (len-- > 0 && ustr[pos] >= 0x80 && ustr[pos] <= 0xbf)
- --pos;
- return pos;
-}
-
 static void normalizeRange(TextField * tPtr, WMRange * range)
 {
  if (range->position < 0 && range->count < 0)
--
2.43.0
0001-WINGs-make-UTF-8-functions-global.patch
Reply all
Reply to author
Forward
0 new messages