Mercurial > vim
comparison 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 |
comparison
equal
deleted
inserted
replaced
31727:2b50a7f0feec | 31728:238ca27dbfd2 |
---|---|
807 * Remove all BOM from "s" by moving remaining text. | 807 * Remove all BOM from "s" by moving remaining text. |
808 */ | 808 */ |
809 void | 809 void |
810 remove_bom(char_u *s) | 810 remove_bom(char_u *s) |
811 { | 811 { |
812 if (enc_utf8) | 812 if (!enc_utf8) |
813 { | 813 return; |
814 char_u *p = s; | 814 |
815 | 815 char_u *p = s; |
816 while ((p = vim_strbyte(p, 0xef)) != NULL) | 816 |
817 { | 817 while ((p = vim_strbyte(p, 0xef)) != NULL) |
818 if (p[1] == 0xbb && p[2] == 0xbf) | 818 { |
819 STRMOVE(p, p + 3); | 819 if (p[1] == 0xbb && p[2] == 0xbf) |
820 else | 820 STRMOVE(p, p + 3); |
821 ++p; | 821 else |
822 } | 822 ++p; |
823 } | 823 } |
824 } | 824 } |
825 #endif | 825 #endif |
826 | 826 |
827 /* | 827 /* |
4588 return vim_strsave(r); | 4588 return vim_strsave(r); |
4589 } | 4589 } |
4590 | 4590 |
4591 // copy "enc" to allocated memory, with room for two '-' | 4591 // copy "enc" to allocated memory, with room for two '-' |
4592 r = alloc(STRLEN(enc) + 3); | 4592 r = alloc(STRLEN(enc) + 3); |
4593 if (r != NULL) | 4593 if (r == NULL) |
4594 { | 4594 return NULL; |
4595 // Make it all lower case and replace '_' with '-'. | 4595 |
4596 p = r; | 4596 // Make it all lower case and replace '_' with '-'. |
4597 for (s = enc; *s != NUL; ++s) | 4597 p = r; |
4598 { | 4598 for (s = enc; *s != NUL; ++s) |
4599 if (*s == '_') | 4599 { |
4600 *p++ = '-'; | 4600 if (*s == '_') |
4601 else | 4601 *p++ = '-'; |
4602 *p++ = TOLOWER_ASC(*s); | 4602 else |
4603 } | 4603 *p++ = TOLOWER_ASC(*s); |
4604 *p = NUL; | 4604 } |
4605 | 4605 *p = NUL; |
4606 // Skip "2byte-" and "8bit-". | 4606 |
4607 p = enc_skip(r); | 4607 // Skip "2byte-" and "8bit-". |
4608 | 4608 p = enc_skip(r); |
4609 // Change "microsoft-cp" to "cp". Used in some spell files. | 4609 |
4610 if (STRNCMP(p, "microsoft-cp", 12) == 0) | 4610 // Change "microsoft-cp" to "cp". Used in some spell files. |
4611 STRMOVE(p, p + 10); | 4611 if (STRNCMP(p, "microsoft-cp", 12) == 0) |
4612 | 4612 STRMOVE(p, p + 10); |
4613 // "iso8859" -> "iso-8859" | 4613 |
4614 if (STRNCMP(p, "iso8859", 7) == 0) | 4614 // "iso8859" -> "iso-8859" |
4615 { | 4615 if (STRNCMP(p, "iso8859", 7) == 0) |
4616 STRMOVE(p + 4, p + 3); | 4616 { |
4617 p[3] = '-'; | 4617 STRMOVE(p + 4, p + 3); |
4618 } | 4618 p[3] = '-'; |
4619 | 4619 } |
4620 // "iso-8859n" -> "iso-8859-n" | 4620 |
4621 if (STRNCMP(p, "iso-8859", 8) == 0 && isdigit(p[8])) | 4621 // "iso-8859n" -> "iso-8859-n" |
4622 { | 4622 if (STRNCMP(p, "iso-8859", 8) == 0 && isdigit(p[8])) |
4623 STRMOVE(p + 9, p + 8); | 4623 { |
4624 p[8] = '-'; | 4624 STRMOVE(p + 9, p + 8); |
4625 } | 4625 p[8] = '-'; |
4626 | 4626 } |
4627 // "latin-N" -> "latinN" | 4627 |
4628 if (STRNCMP(p, "latin-", 6) == 0) | 4628 // "latin-N" -> "latinN" |
4629 STRMOVE(p + 5, p + 6); | 4629 if (STRNCMP(p, "latin-", 6) == 0) |
4630 | 4630 STRMOVE(p + 5, p + 6); |
4631 if (enc_canon_search(p) >= 0) | 4631 |
4632 { | 4632 if (enc_canon_search(p) >= 0) |
4633 // canonical name can be used unmodified | 4633 { |
4634 if (p != r) | 4634 // canonical name can be used unmodified |
4635 STRMOVE(r, p); | 4635 if (p != r) |
4636 } | 4636 STRMOVE(r, p); |
4637 else if ((i = enc_alias_search(p)) >= 0) | 4637 } |
4638 { | 4638 else if ((i = enc_alias_search(p)) >= 0) |
4639 // alias recognized, get canonical name | 4639 { |
4640 vim_free(r); | 4640 // alias recognized, get canonical name |
4641 r = vim_strsave((char_u *)enc_canon_table[i].name); | 4641 vim_free(r); |
4642 } | 4642 r = vim_strsave((char_u *)enc_canon_table[i].name); |
4643 } | 4643 } |
4644 return r; | 4644 return r; |
4645 } | 4645 } |
4646 | 4646 |
4647 /* | 4647 /* |
5267 int dlen = len; | 5267 int dlen = len; |
5268 int unconvertlen = 0; | 5268 int unconvertlen = 0; |
5269 | 5269 |
5270 d = string_convert_ext(&input_conv, ptr, &dlen, | 5270 d = string_convert_ext(&input_conv, ptr, &dlen, |
5271 restp == NULL ? NULL : &unconvertlen); | 5271 restp == NULL ? NULL : &unconvertlen); |
5272 if (d != NULL) | 5272 if (d == NULL) |
5273 { | 5273 return dlen; |
5274 if (dlen <= maxlen) | 5274 |
5275 if (dlen <= maxlen) | |
5276 { | |
5277 if (unconvertlen > 0) | |
5275 { | 5278 { |
5276 if (unconvertlen > 0) | 5279 // Move the unconverted characters to allocated memory. |
5277 { | 5280 *restp = alloc(unconvertlen); |
5278 // Move the unconverted characters to allocated memory. | 5281 if (*restp != NULL) |
5279 *restp = alloc(unconvertlen); | 5282 mch_memmove(*restp, ptr + len - unconvertlen, unconvertlen); |
5280 if (*restp != NULL) | 5283 *restlenp = unconvertlen; |
5281 mch_memmove(*restp, ptr + len - unconvertlen, unconvertlen); | |
5282 *restlenp = unconvertlen; | |
5283 } | |
5284 mch_memmove(ptr, d, dlen); | |
5285 } | 5284 } |
5286 else | 5285 mch_memmove(ptr, d, dlen); |
5287 // result is too long, keep the unconverted text (the caller must | 5286 } |
5288 // have done something wrong!) | 5287 else |
5289 dlen = len; | 5288 // result is too long, keep the unconverted text (the caller must |
5290 vim_free(d); | 5289 // have done something wrong!) |
5291 } | 5290 dlen = len; |
5291 vim_free(d); | |
5292 return dlen; | 5292 return dlen; |
5293 } | 5293 } |
5294 | 5294 |
5295 /* | 5295 /* |
5296 * Convert text "ptr[*lenp]" according to "vcp". | 5296 * Convert text "ptr[*lenp]" according to "vcp". |