diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-03-13 01:45:24 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-03-13 01:45:24 -0400 |
commit | cdeead908ce29dccccad2043295f1a58f6f0f347 (patch) | |
tree | c9082bb61e0d4726b4f13d07bb63604614d01e4b /src/manifest.c | |
parent | 1035f19057595ed44ae2e4463ab6f533ee7bd50e (diff) | |
download | spmc-cdeead908ce29dccccad2043295f1a58f6f0f347.tar.gz |
Simplify manifest_package_separator_swap function
Diffstat (limited to 'src/manifest.c')
-rw-r--r-- | src/manifest.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/manifest.c b/src/manifest.c index 878ab5b..cc45346 100644 --- a/src/manifest.c +++ b/src/manifest.c @@ -25,15 +25,17 @@ int manifest_package_cmp(ManifestPackage *a, ManifestPackage *b) { void manifest_package_separator_swap(char **name) { // Replace unwanted separators in the package name with placeholder to prevent splitting on the wrong one - int delim_count = num_chars((*name), SPM_PACKAGE_MEMBER_SEPARATOR); - if (delim_count > PACKAGE_MIN_DELIM) { - for (size_t t = strlen((*name)); t != 0; t--) { - if ((*name)[t] == SPM_PACKAGE_MEMBER_SEPARATOR) { - delim_count--; - if (delim_count == 0) { - (*name)[t] = SPM_PACKAGE_MEMBER_SEPARATOR_PLACEHOLD; - } - } + int delim_count = num_chars((*name), SPM_PACKAGE_MEMBER_SEPARATOR) - PACKAGE_MIN_DELIM; + + if (delim_count < 0) { + return; + } + + for (size_t t = 0; t < strlen((*name)); t++) { + if (delim_count == 0) break; + if ((*name)[t] == SPM_PACKAGE_MEMBER_SEPARATOR) { + (*name)[t] = SPM_PACKAGE_MEMBER_SEPARATOR_PLACEHOLD; + delim_count--; } } } |