From 74620db49f0f68b5be6f78aa49672e2f7f4e76aa Mon Sep 17 00:00:00 2001 From: Ryan Curtin Date: Tue, 20 Aug 2019 13:06:25 -0400 Subject: [PATCH] Use std::replace(). --- src/mlpack/bindings/julia/strip_type.hpp | 33 +++++++----------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/src/mlpack/bindings/julia/strip_type.hpp b/src/mlpack/bindings/julia/strip_type.hpp index c789a7723a..3a2a179ac1 100644 --- a/src/mlpack/bindings/julia/strip_type.hpp +++ b/src/mlpack/bindings/julia/strip_type.hpp @@ -23,29 +23,16 @@ namespace julia { inline std::string StripType(std::string cppType) { // Basically what we need to do is strip any '<' (template bits) from the - // type. - if (cppType.find("<") != std::string::npos) - { - // Are there any template parameters? Or is it the default? - const size_t loc = cppType.find("<>"); - if (loc != std::string::npos) - { - // Convert it from "<>". - cppType.replace(loc, 2, ""); - } - else - { - // Let's just replace the '<' and '>' with a valid '_' character. - while (cppType.find("<") != std::string::npos) - cppType.replace(cppType.find("<"), 1, "_"); - while (cppType.find(">") != std::string::npos) - cppType.replace(cppType.find(">"), 1, "_"); - while (cppType.find(" ") != std::string::npos) - cppType.replace(cppType.find(" "), 1, "_"); - while (cppType.find(",") != std::string::npos) - cppType.replace(cppType.find(","), 1, "_"); - } - } + // type. We'll try first by removing any instances of <>. + const size_t loc = cppType.find("<>"); + if (loc != std::string::npos) + cppType.replace(loc, 2, ""); + + // Let's just replace any invalid characters with valid '_' characters. + std::replace(cppType.begin(), cppType.end(), '<', '_'); + std::replace(cppType.begin(), cppType.end(), '>', '_'); + std::replace(cppType.begin(), cppType.end(), ' ', '_'); + std::replace(cppType.begin(), cppType.end(), ',', '_'); return cppType; }