From da2925e920407eabdb3021177e5f38f0e09abe12 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sun, 1 Nov 2015 03:39:56 -0800 Subject: [PATCH] Fix the name stripping logic --- src/corehost/inc/utils.h | 3 ++- src/corehost/src/args.cpp | 3 ++- src/corehost/src/utils.cpp | 16 +++++++++------- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/corehost/inc/utils.h b/src/corehost/inc/utils.h index 60a152c58..717e18466 100644 --- a/src/corehost/inc/utils.h +++ b/src/corehost/inc/utils.h @@ -3,7 +3,8 @@ #include "pal.h" -pal::string_t change_extension(const pal::string_t& filename, const pal::char_t* new_extension); +bool ends_with(const pal::string_t& value, const pal::string_t& suffix); +pal::string_t get_executable(const pal::string_t& filename); pal::string_t get_directory(const pal::string_t& path); pal::string_t get_filename(const pal::string_t& path); void append_path(pal::string_t& path1, const pal::char_t* path2); diff --git a/src/corehost/src/args.cpp b/src/corehost/src/args.cpp index 29bca3e6b..1824391c8 100644 --- a/src/corehost/src/args.cpp +++ b/src/corehost/src/args.cpp @@ -49,7 +49,8 @@ bool parse_arguments(const int argc, const pal::char_t* argv[], arguments_t& arg // coreconsole mode. Find the managed app in the same directory pal::string_t managed_app(own_dir); managed_app.push_back(DIR_SEPARATOR); - managed_app.append(change_extension(own_name, _X(".dll"))); + managed_app.append(get_executable(own_name)); + managed_app.append(_X(".dll")); args.managed_application = managed_app; args.app_argv = &argv[1]; args.app_argc = argc - 1; diff --git a/src/corehost/src/utils.cpp b/src/corehost/src/utils.cpp index 9e3c14f3f..80b9a0f60 100644 --- a/src/corehost/src/utils.cpp +++ b/src/corehost/src/utils.cpp @@ -16,22 +16,24 @@ void append_path(pal::string_t& path1, const pal::char_t* path2) } } -pal::string_t change_extension(const pal::string_t& filename, const pal::char_t* new_extension) +pal::string_t get_executable(const pal::string_t& filename) { pal::string_t result(filename); - auto ext_sep = result.find_last_of('.'); - if (ext_sep != pal::string_t::npos) + if (ends_with(result, _X(".exe"))) { // We need to strip off the old extension - result.erase(ext_sep); + result.erase(result.length() - 4); } - - // Append the new extension - result.append(new_extension); + return result; } +bool ends_with(const pal::string_t& value, const pal::string_t& suffix) +{ + return (0 == value.compare(value.length() - suffix.length(), suffix.length(), suffix)); +} + pal::string_t get_filename(const pal::string_t& path) { // Find the last dir separator