📄 ucpgba.c
字号:
* Determine the next run of LTR text. */ ld = s; while (e < end && ISLTR_LTR(source[e])) { if (ucisdigit(source[e]) && !(0x660 <= source[e] && source[e] <= 0x669)) ld = e; e++; } if (str->direction != UCPGBA_LTR) { while (e > ld && ISWEAK_NEUTRAL(source[e - 1])) e--; } /* * Add the LTR segment to the string. */ if (e > s) _ucadd_ltr_segment(str, source, s, e); } /* * Determine the next run of RTL text. */ ld = s = e; while (e < end && ISRTL_RTL(source[e])) { if (ucisdigit(source[e]) && !(0x660 <= source[e] && source[e] <= 0x669)) ld = e; e++; } if (str->direction != UCPGBA_RTL) { while (e > ld && ISWEAK_NEUTRAL(source[e - 1])) e--; } /* * Add the RTL segment to the string. */ if (e > s) _ucadd_rtl_segment(str, source, s, e); /* * Clear the flag that allowed the RTL collection loop to run first * for strings with overall RTL directionality. */ rtl_first = 0; } /* * Set up the initial cursor run. */ str->cursor = str->logical_first; if (str != 0) str->cursor->cursor = (str->cursor->direction == UCPGBA_RTL) ? str->cursor->end - str->cursor->start : 0; return str;}voiducstring_free(ucstring_t *s){ ucrun_t *l, *r; if (s == 0) return; for (l = 0, r = s->visual_first; r != 0; r = r->visual_next) { if (r->end > r->start) free((char *) r->chars); if (l) free((char *) l); l = r; } if (l) free((char *) l); free((char *) s);}intucstring_set_cursor_motion(ucstring_t *str, int cursor_motion){ int n; if (str == 0) return -1; n = str->cursor_motion; str->cursor_motion = cursor_motion; return n;}static int_ucstring_visual_cursor_right(ucstring_t *str, int count){ int cnt = count; unsigned long size; ucrun_t *cursor; if (str == 0) return 0; cursor = str->cursor; while (cnt > 0) { size = cursor->end - cursor->start; if ((cursor->direction == UCPGBA_RTL && cursor->cursor + 1 == size) || cursor->cursor + 1 > size) { /* * If the next run is NULL, then the cursor is already on the * far right end already. */ if (cursor->visual_next == 0) /* * If movement occured, then report it. */ return (cnt != count); /* * Move to the next run. */ str->cursor = cursor = cursor->visual_next; cursor->cursor = (cursor->direction == UCPGBA_RTL) ? -1 : 0; size = cursor->end - cursor->start; } else cursor->cursor++; cnt--; } return 1;}static int_ucstring_logical_cursor_right(ucstring_t *str, int count){ int cnt = count; unsigned long size; ucrun_t *cursor; if (str == 0) return 0; cursor = str->cursor; while (cnt > 0) { size = cursor->end - cursor->start; if (str->direction == UCPGBA_RTL) { if (cursor->direction == UCPGBA_RTL) { if (cursor->cursor + 1 == size) { if (cursor == str->logical_first) /* * Already at the beginning of the string. */ return (cnt != count); str->cursor = cursor = cursor->logical_prev; size = cursor->end - cursor->start; cursor->cursor = (cursor->direction == UCPGBA_LTR) ? size : 0; } else cursor->cursor++; } else { if (cursor->cursor == 0) { if (cursor == str->logical_first) /* * At the beginning of the string already. */ return (cnt != count); str->cursor = cursor = cursor->logical_prev; size = cursor->end - cursor->start; cursor->cursor = (cursor->direction == UCPGBA_LTR) ? size : 0; } else cursor->cursor--; } } else { if (cursor->direction == UCPGBA_RTL) { if (cursor->cursor == 0) { if (cursor == str->logical_last) /* * Already at the end of the string. */ return (cnt != count); str->cursor = cursor = cursor->logical_next; size = cursor->end - cursor->start; cursor->cursor = (cursor->direction == UCPGBA_LTR) ? 0 : size - 1; } else cursor->cursor--; } else { if (cursor->cursor + 1 > size) { if (cursor == str->logical_last) /* * Already at the end of the string. */ return (cnt != count); str->cursor = cursor = cursor->logical_next; cursor->cursor = (cursor->direction == UCPGBA_LTR) ? 0 : size - 1; } else cursor->cursor++; } } cnt--; } return 1;}intucstring_cursor_right(ucstring_t *str, int count){ if (str == 0) return 0; return (str->cursor_motion == UCPGBA_CURSOR_VISUAL) ? _ucstring_visual_cursor_right(str, count) : _ucstring_logical_cursor_right(str, count);}static int_ucstring_visual_cursor_left(ucstring_t *str, int count){ int cnt = count; unsigned long size; ucrun_t *cursor; if (str == 0) return 0; cursor = str->cursor; while (cnt > 0) { size = cursor->end - cursor->start; if ((cursor->direction == UCPGBA_LTR && cursor->cursor == 0) || cursor->cursor - 1 < -1) { /* * If the preceding run is NULL, then the cursor is already on the * far left end already. */ if (cursor->visual_prev == 0) /* * If movement occured, then report it. */ return (cnt != count); /* * Move to the previous run. */ str->cursor = cursor = cursor->visual_prev; size = cursor->end - cursor->start; cursor->cursor = (cursor->direction == UCPGBA_RTL) ? size : size - 1; } else cursor->cursor--; cnt--; } return 1;}static int_ucstring_logical_cursor_left(ucstring_t *str, int count){ int cnt = count; unsigned long size; ucrun_t *cursor; if (str == 0) return 0; cursor = str->cursor; while (cnt > 0) { size = cursor->end - cursor->start; if (str->direction == UCPGBA_RTL) { if (cursor->direction == UCPGBA_RTL) { if (cursor->cursor == -1) { if (cursor == str->logical_last) /* * Already at the end of the string. */ return (cnt != count); str->cursor = cursor = cursor->logical_next; size = cursor->end - cursor->start; cursor->cursor = (cursor->direction == UCPGBA_LTR) ? 0 : size - 1; } else cursor->cursor--; } else { if (cursor->cursor + 1 > size) { if (cursor == str->logical_last) /* * At the end of the string already. */ return (cnt != count); str->cursor = cursor = cursor->logical_next; size = cursor->end - cursor->start; cursor->cursor = (cursor->direction == UCPGBA_LTR) ? 0 : size - 1; } else cursor->cursor++; } } else { if (cursor->direction == UCPGBA_RTL) { if (cursor->cursor + 1 == size) { if (cursor == str->logical_first) /* * Already at the beginning of the string. */ return (cnt != count); str->cursor = cursor = cursor->logical_prev; size = cursor->end - cursor->start; cursor->cursor = (cursor->direction == UCPGBA_LTR) ? size : 0; } else cursor->cursor++; } else { if (cursor->cursor == 0) { if (cursor == str->logical_first) /* * Already at the beginning of the string. */ return (cnt != count); str->cursor = cursor = cursor->logical_prev; cursor->cursor = (cursor->direction == UCPGBA_LTR) ? size : 0; } else cursor->cursor--; } } cnt--; } return 1;}intucstring_cursor_left(ucstring_t *str, int count){ if (str == 0) return 0; return (str->cursor_motion == UCPGBA_CURSOR_VISUAL) ? _ucstring_visual_cursor_left(str, count) : _ucstring_logical_cursor_left(str, count);}voiducstring_cursor_info(ucstring_t *str, int *direction, unsigned long *position){ long c; unsigned long size; ucrun_t *cursor; if (str == 0 || direction == 0 || position == 0) return; cursor = str->cursor; *direction = cursor->direction; c = cursor->cursor; size = cursor->end - cursor->start; if (c == size) *position = (cursor->direction == UCPGBA_RTL) ? cursor->start : cursor->positions[c - 1]; else if (c == -1) *position = (cursor->direction == UCPGBA_RTL) ? cursor->end : cursor->start; else *position = cursor->positions[c];}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -