1
0
forked from aniani/vim

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)
This commit is contained in:
Yegappan Lakshmanan
2023-01-14 12:32:28 +00:00
committed by Bram Moolenaar
parent 378e6c03f9
commit e857598896
16 changed files with 678 additions and 676 deletions

View File

@@ -809,17 +809,17 @@ bomb_size(void)
void
remove_bom(char_u *s)
{
if (enc_utf8)
{
char_u *p = s;
if (!enc_utf8)
return;
while ((p = vim_strbyte(p, 0xef)) != NULL)
{
if (p[1] == 0xbb && p[2] == 0xbf)
STRMOVE(p, p + 3);
else
++p;
}
char_u *p = s;
while ((p = vim_strbyte(p, 0xef)) != NULL)
{
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)
{
// 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;
if (*s == '_')
*p++ = '-';
else
*p++ = TOLOWER_ASC(*s);
}
*p = NUL;
// Skip "2byte-" and "8bit-".
p = enc_skip(r);
// 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);
// 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] = '-';
}
// "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] = '-';
}
// "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);
// "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);
}
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;
}