Mercurial > vim
comparison src/spellsuggest.c @ 18251:c8a53c0daeed v8.1.2120
patch 8.1.2120: some MB_ macros are more complicated than necessary
Commit: https://github.com/vim/vim/commit/1614a14901558ca091329315d14a7d5e1b53aa47
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Oct 6 22:00:13 2019 +0200
patch 8.1.2120: some MB_ macros are more complicated than necessary
Problem: Some MB_ macros are more complicated than necessary. (Dominique
Pelle)
Solution: Simplify the macros. Expand inline.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 06 Oct 2019 22:15:04 +0200 |
parents | 6e53d83e021d |
children | 9e6d5a4abb1c |
comparison
equal
deleted
inserted
replaced
18250:f1d9d3f76c98 | 18251:c8a53c0daeed |
---|---|
1780 && fword[sp->ts_fidx] != NUL | 1780 && fword[sp->ts_fidx] != NUL |
1781 && goodword_ends) | 1781 && goodword_ends) |
1782 { | 1782 { |
1783 int l; | 1783 int l; |
1784 | 1784 |
1785 l = MB_PTR2LEN(fword + sp->ts_fidx); | 1785 l = mb_ptr2len(fword + sp->ts_fidx); |
1786 if (fword_ends) | 1786 if (fword_ends) |
1787 { | 1787 { |
1788 // Copy the skipped character to preword. | 1788 // Copy the skipped character to preword. |
1789 mch_memmove(preword + sp->ts_prewordlen, | 1789 mch_memmove(preword + sp->ts_prewordlen, |
1790 fword + sp->ts_fidx, l); | 1790 fword + sp->ts_fidx, l); |
1935 if (sp->ts_isdiff == DIFF_YES) | 1935 if (sp->ts_isdiff == DIFF_YES) |
1936 { | 1936 { |
1937 // Correct ts_fidx for the byte length of the | 1937 // Correct ts_fidx for the byte length of the |
1938 // character (we didn't check that before). | 1938 // character (we didn't check that before). |
1939 sp->ts_fidx = sp->ts_fcharstart | 1939 sp->ts_fidx = sp->ts_fcharstart |
1940 + MB_PTR2LEN( | 1940 + mb_ptr2len( |
1941 fword + sp->ts_fcharstart); | 1941 fword + sp->ts_fcharstart); |
1942 // For changing a composing character adjust | 1942 // For changing a composing character adjust |
1943 // the score from SCORE_SUBST to | 1943 // the score from SCORE_SUBST to |
1944 // SCORE_SUBCOMP. | 1944 // SCORE_SUBCOMP. |
1945 if (enc_utf8 | 1945 if (enc_utf8 |
2051 // a bit illogical for soundfold tree but it does give better | 2051 // a bit illogical for soundfold tree but it does give better |
2052 // results. | 2052 // results. |
2053 if (has_mbyte) | 2053 if (has_mbyte) |
2054 { | 2054 { |
2055 c = mb_ptr2char(fword + sp->ts_fidx); | 2055 c = mb_ptr2char(fword + sp->ts_fidx); |
2056 stack[depth].ts_fidx += MB_PTR2LEN(fword + sp->ts_fidx); | 2056 stack[depth].ts_fidx += mb_ptr2len(fword + sp->ts_fidx); |
2057 if (enc_utf8 && utf_iscomposing(c)) | 2057 if (enc_utf8 && utf_iscomposing(c)) |
2058 stack[depth].ts_score -= SCORE_DEL - SCORE_DELCOMP; | 2058 stack[depth].ts_score -= SCORE_DEL - SCORE_DELCOMP; |
2059 else if (c == mb_ptr2char(fword + stack[depth].ts_fidx)) | 2059 else if (c == mb_ptr2char(fword + stack[depth].ts_fidx)) |
2060 stack[depth].ts_score -= SCORE_DEL - SCORE_DELDUP; | 2060 stack[depth].ts_score -= SCORE_DEL - SCORE_DELDUP; |
2061 } | 2061 } |
2264 case STATE_UNSWAP: | 2264 case STATE_UNSWAP: |
2265 // Undo the STATE_SWAP swap: "21" -> "12". | 2265 // Undo the STATE_SWAP swap: "21" -> "12". |
2266 p = fword + sp->ts_fidx; | 2266 p = fword + sp->ts_fidx; |
2267 if (has_mbyte) | 2267 if (has_mbyte) |
2268 { | 2268 { |
2269 n = MB_PTR2LEN(p); | 2269 n = mb_ptr2len(p); |
2270 c = mb_ptr2char(p + n); | 2270 c = mb_ptr2char(p + n); |
2271 mch_memmove(p + MB_PTR2LEN(p + n), p, n); | 2271 mch_memmove(p + mb_ptr2len(p + n), p, n); |
2272 mb_char2bytes(c, p); | 2272 mb_char2bytes(c, p); |
2273 } | 2273 } |
2274 else | 2274 else |
2275 { | 2275 { |
2276 c = *p; | 2276 c = *p; |
2352 case STATE_UNSWAP3: | 2352 case STATE_UNSWAP3: |
2353 // Undo STATE_SWAP3: "321" -> "123" | 2353 // Undo STATE_SWAP3: "321" -> "123" |
2354 p = fword + sp->ts_fidx; | 2354 p = fword + sp->ts_fidx; |
2355 if (has_mbyte) | 2355 if (has_mbyte) |
2356 { | 2356 { |
2357 n = MB_PTR2LEN(p); | 2357 n = mb_ptr2len(p); |
2358 c2 = mb_ptr2char(p + n); | 2358 c2 = mb_ptr2char(p + n); |
2359 fl = MB_PTR2LEN(p + n); | 2359 fl = mb_ptr2len(p + n); |
2360 c = mb_ptr2char(p + n + fl); | 2360 c = mb_ptr2char(p + n + fl); |
2361 tl = MB_PTR2LEN(p + n + fl); | 2361 tl = mb_ptr2len(p + n + fl); |
2362 mch_memmove(p + fl + tl, p, n); | 2362 mch_memmove(p + fl + tl, p, n); |
2363 mb_char2bytes(c, p); | 2363 mb_char2bytes(c, p); |
2364 mb_char2bytes(c2, p + tl); | 2364 mb_char2bytes(c2, p + tl); |
2365 p = p + tl; | 2365 p = p + tl; |
2366 } | 2366 } |
2425 case STATE_UNROT3L: | 2425 case STATE_UNROT3L: |
2426 // Undo ROT3L: "231" -> "123" | 2426 // Undo ROT3L: "231" -> "123" |
2427 p = fword + sp->ts_fidx; | 2427 p = fword + sp->ts_fidx; |
2428 if (has_mbyte) | 2428 if (has_mbyte) |
2429 { | 2429 { |
2430 n = MB_PTR2LEN(p); | 2430 n = mb_ptr2len(p); |
2431 n += MB_PTR2LEN(p + n); | 2431 n += mb_ptr2len(p + n); |
2432 c = mb_ptr2char(p + n); | 2432 c = mb_ptr2char(p + n); |
2433 tl = MB_PTR2LEN(p + n); | 2433 tl = mb_ptr2len(p + n); |
2434 mch_memmove(p + tl, p, n); | 2434 mch_memmove(p + tl, p, n); |
2435 mb_char2bytes(c, p); | 2435 mb_char2bytes(c, p); |
2436 } | 2436 } |
2437 else | 2437 else |
2438 { | 2438 { |
2487 // Undo ROT3R: "312" -> "123" | 2487 // Undo ROT3R: "312" -> "123" |
2488 p = fword + sp->ts_fidx; | 2488 p = fword + sp->ts_fidx; |
2489 if (has_mbyte) | 2489 if (has_mbyte) |
2490 { | 2490 { |
2491 c = mb_ptr2char(p); | 2491 c = mb_ptr2char(p); |
2492 tl = MB_PTR2LEN(p); | 2492 tl = mb_ptr2len(p); |
2493 n = MB_PTR2LEN(p + tl); | 2493 n = mb_ptr2len(p + tl); |
2494 n += MB_PTR2LEN(p + tl + n); | 2494 n += mb_ptr2len(p + tl + n); |
2495 mch_memmove(p, p + tl, n); | 2495 mch_memmove(p, p + tl, n); |
2496 mb_char2bytes(c, p + n); | 2496 mb_char2bytes(c, p + n); |
2497 } | 2497 } |
2498 else | 2498 else |
2499 { | 2499 { |