Mercurial > vim
diff src/mbyte.c @ 31728:238ca27dbfd2 v9.0.1196
patch 9.0.1196: code is indented more than necessary
Commit: https://github.com/vim/vim/commit/e8575988969579f9e1439181ae338b2ff74054a8
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Sat Jan 14 12:32:28 2023 +0000
patch 9.0.1196: code is indented more than necessary
Problem: Code is indented more than necessary.
Solution: Use an early return where it makes sense. (Yegappan Lakshmanan,
closes #11813)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 14 Jan 2023 13:45:04 +0100 |
parents | 9e1062b4aa94 |
children | f348559ce426 |
line wrap: on
line diff
--- a/src/mbyte.c +++ b/src/mbyte.c @@ -809,17 +809,17 @@ bomb_size(void) void remove_bom(char_u *s) { - if (enc_utf8) + if (!enc_utf8) + return; + + char_u *p = s; + + while ((p = vim_strbyte(p, 0xef)) != NULL) { - char_u *p = s; - - while ((p = vim_strbyte(p, 0xef)) != NULL) - { - if (p[1] == 0xbb && p[2] == 0xbf) - STRMOVE(p, p + 3); - else - ++p; - } + if (p[1] == 0xbb && p[2] == 0xbf) + STRMOVE(p, p + 3); + else + ++p; } } #endif @@ -4590,56 +4590,56 @@ enc_canonize(char_u *enc) // copy "enc" to allocated memory, with room for two '-' r = alloc(STRLEN(enc) + 3); - if (r != NULL) + if (r == NULL) + return NULL; + + // Make it all lower case and replace '_' with '-'. + p = r; + for (s = enc; *s != NUL; ++s) + { + if (*s == '_') + *p++ = '-'; + else + *p++ = TOLOWER_ASC(*s); + } + *p = NUL; + + // Skip "2byte-" and "8bit-". + p = enc_skip(r); + + // Change "microsoft-cp" to "cp". Used in some spell files. + if (STRNCMP(p, "microsoft-cp", 12) == 0) + STRMOVE(p, p + 10); + + // "iso8859" -> "iso-8859" + if (STRNCMP(p, "iso8859", 7) == 0) { - // Make it all lower case and replace '_' with '-'. - p = r; - for (s = enc; *s != NUL; ++s) - { - if (*s == '_') - *p++ = '-'; - else - *p++ = TOLOWER_ASC(*s); - } - *p = NUL; - - // Skip "2byte-" and "8bit-". - p = enc_skip(r); - - // Change "microsoft-cp" to "cp". Used in some spell files. - if (STRNCMP(p, "microsoft-cp", 12) == 0) - STRMOVE(p, p + 10); - - // "iso8859" -> "iso-8859" - if (STRNCMP(p, "iso8859", 7) == 0) - { - STRMOVE(p + 4, p + 3); - p[3] = '-'; - } - - // "iso-8859n" -> "iso-8859-n" - if (STRNCMP(p, "iso-8859", 8) == 0 && isdigit(p[8])) - { - STRMOVE(p + 9, p + 8); - p[8] = '-'; - } - - // "latin-N" -> "latinN" - if (STRNCMP(p, "latin-", 6) == 0) - STRMOVE(p + 5, p + 6); - - if (enc_canon_search(p) >= 0) - { - // canonical name can be used unmodified - if (p != r) - STRMOVE(r, p); - } - else if ((i = enc_alias_search(p)) >= 0) - { - // alias recognized, get canonical name - vim_free(r); - r = vim_strsave((char_u *)enc_canon_table[i].name); - } + STRMOVE(p + 4, p + 3); + p[3] = '-'; + } + + // "iso-8859n" -> "iso-8859-n" + if (STRNCMP(p, "iso-8859", 8) == 0 && isdigit(p[8])) + { + STRMOVE(p + 9, p + 8); + p[8] = '-'; + } + + // "latin-N" -> "latinN" + if (STRNCMP(p, "latin-", 6) == 0) + STRMOVE(p + 5, p + 6); + + if (enc_canon_search(p) >= 0) + { + // canonical name can be used unmodified + if (p != r) + STRMOVE(r, p); + } + else if ((i = enc_alias_search(p)) >= 0) + { + // alias recognized, get canonical name + vim_free(r); + r = vim_strsave((char_u *)enc_canon_table[i].name); } return r; } @@ -5269,26 +5269,26 @@ convert_input_safe( d = string_convert_ext(&input_conv, ptr, &dlen, restp == NULL ? NULL : &unconvertlen); - if (d != NULL) + if (d == NULL) + return dlen; + + if (dlen <= maxlen) { - if (dlen <= maxlen) + if (unconvertlen > 0) { - if (unconvertlen > 0) - { - // Move the unconverted characters to allocated memory. - *restp = alloc(unconvertlen); - if (*restp != NULL) - mch_memmove(*restp, ptr + len - unconvertlen, unconvertlen); - *restlenp = unconvertlen; - } - mch_memmove(ptr, d, dlen); + // Move the unconverted characters to allocated memory. + *restp = alloc(unconvertlen); + if (*restp != NULL) + mch_memmove(*restp, ptr + len - unconvertlen, unconvertlen); + *restlenp = unconvertlen; } - else - // result is too long, keep the unconverted text (the caller must - // have done something wrong!) - dlen = len; - vim_free(d); + mch_memmove(ptr, d, dlen); } + else + // result is too long, keep the unconverted text (the caller must + // have done something wrong!) + dlen = len; + vim_free(d); return dlen; }