Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed file src/nupic/utils/StringUtils.hpp #496

Merged
merged 1 commit into from
Jun 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions bindings/py/cpp_src/bindings/sdr/py_SDR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <pybind11/stl.h>

#include <nupic/types/Sdr.hpp>
#include <nupic/utils/StringUtils.hpp> // trim

#include <memory> // shared_ptr

Expand Down Expand Up @@ -292,7 +291,7 @@ magic seed 0. Use the same seed to consistently kill the same cells.)",
py_SDR.def("__str__", [](SDR &self){
stringstream buf;
buf << self;
return StringUtils::trim( buf.str() ); });
return py::str( buf.str() ).attr("strip")(); });

py_SDR.def("__eq__", [](SDR &self, SDR &other){ return self == other; });
py_SDR.def("__ne__", [](SDR &self, SDR &other){ return self != other; });
Expand Down
9 changes: 4 additions & 5 deletions bindings/py/cpp_src/bindings/sdr/py_SDR_Metrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <pybind11/numpy.h>

#include <nupic/utils/SdrMetrics.hpp>
#include <nupic/utils/StringUtils.hpp> // trim

namespace py = pybind11;

Expand Down Expand Up @@ -95,7 +94,7 @@ Argument period is time constant for exponential moving average.)",
py_Sparsity.def("__str__", [](Sparsity &self){
stringstream buf;
buf << self;
return StringUtils::trim( buf.str() );
return py::str( buf.str() ).attr("strip")();
});

// =====================================================================
Expand Down Expand Up @@ -172,7 +171,7 @@ Returns binary entropy of SDR, scaled to range [0, 1].)");
py_ActivationFrequency.def("__str__", [](ActivationFrequency &self){
stringstream buf;
buf << self;
return StringUtils::trim( buf.str() );
return py::str( buf.str() ).attr("strip")();
});

// =====================================================================
Expand Down Expand Up @@ -221,7 +220,7 @@ Argument period is time constant for exponential moving average.)",
py_Overlap.def("__str__", [](Overlap &self){
stringstream buf;
buf << self;
return StringUtils::trim( buf.str() );
return py::str( buf.str() ).attr("strip")();
});

// =====================================================================
Expand Down Expand Up @@ -282,7 +281,7 @@ dimensions.)", py::arg("sdr"));
py_Metrics.def("__str__", [](Metrics &self){
stringstream buf;
buf << self;
return StringUtils::trim( buf.str() );
return py::str( buf.str() ).attr("strip")();
});
}
}
2 changes: 0 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,6 @@ set(utils_files
nupic/utils/Random.cpp
nupic/utils/Random.hpp
nupic/utils/SlidingWindow.hpp
nupic/utils/StringUtils.cpp
nupic/utils/StringUtils.hpp
nupic/utils/VectorHelpers.hpp
nupic/utils/SdrMetrics.cpp
nupic/utils/SdrMetrics.hpp
Expand Down
1 change: 0 additions & 1 deletion src/nupic/engine/Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ Implementation of the Network class
#include <nupic/os/Path.hpp>
#include <nupic/ntypes/BasicType.hpp>
#include <nupic/utils/Log.hpp>
#include <nupic/utils/StringUtils.hpp>

namespace nupic {

Expand Down
1 change: 0 additions & 1 deletion src/nupic/engine/RegionImplFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@


#include <nupic/utils/Log.hpp>
#include <nupic/utils/StringUtils.hpp>

// from http://stackoverflow.com/a/9096509/1781435
#define stringify(x) #x
Expand Down
21 changes: 15 additions & 6 deletions src/nupic/os/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
#include <nupic/os/OS.hpp>
#include <nupic/os/Path.hpp>
#include <nupic/utils/Log.hpp>
#include <nupic/utils/StringUtils.hpp> // for trim
#include <algorithm> // replace()
#include <sstream>
#include <string>
#include <iterator>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <cctype> // isspace
#if defined(NTA_OS_WINDOWS)
#include <io.h>
#else
Expand All @@ -54,6 +54,15 @@ const char *Path::sep = "/";
const char *Path::pathSep = ":";
#endif

std::string trim(const std::string &s) {
size_t i,j;
for(i = 0; i < s.length(); i++)
if (!std::isspace(s[i])) break;
for(j = s.length(); j > i; j--)
if (!std::isspace(s[j-1])) break;
return s.substr(i, j-i);
}

bool Path::exists(const std::string &path) { return fs::exists(path); }

bool Path::equals(const std::string &path1, const std::string &path2) {
Expand Down Expand Up @@ -145,7 +154,7 @@ Size Path::getFileSize(const std::string &path) {
* Replace this when everyone is using C++17 or better.
*/
std::string Path::normalize(const std::string &path) {
std::string trimmed_path = StringUtils::trim(path);
std::string trimmed_path = trim(path);
if (trimmed_path.empty()) return ".";
std::replace(trimmed_path.begin(), trimmed_path.end(), '\\', '/'); // in-place replace
fs::path p(trimmed_path);
Expand All @@ -161,17 +170,17 @@ std::string Path::normalize(const std::string &path) {
if (p.has_root_path()) normal_p.push_back((iter++)->string());
size_t j = normal_p.size(); // minimum size.
for ( ; iter != p.end(); iter++) {
std::string ele = StringUtils::trim(iter->string());
std::string ele = trim(iter->string());
if (ele == "." || ele == "") continue;
if (ele == ".." && normal_p.size() > j && normal_p.back() != "..") {
normal_p.pop_back();
continue;
}
normal_p.push_back(ele);
}
normal_p.push_back(ele);
}
fs::path new_p;
for(auto& ele : normal_p) {
new_p /= ele;
new_p /= ele;
}
new_p = new_p.make_preferred();
std::string result = new_p.string();
Expand Down
17 changes: 12 additions & 5 deletions src/nupic/regions/VectorFileSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,20 @@
#include <nupic/engine/Spec.hpp>
#include <nupic/regions/VectorFileSensor.hpp>
#include <nupic/utils/Log.hpp>
#include <nupic/utils/StringUtils.hpp>
#include <nupic/ntypes/BundleIO.hpp>
#include <nupic/ntypes/Value.hpp>

using namespace std;
namespace nupic {

// Helper function
UInt32 toUInt32(const std::string& s) {
std::istringstream ss(s);
UInt32 i;
ss >> i;
return i;
}

//----------------------------------------------------------------------------

VectorFileSensor::VectorFileSensor(const ValueMap &params, Region *region)
Expand Down Expand Up @@ -186,7 +193,7 @@ std::string VectorFileSensor::executeCommand(const std::vector<std::string>& arg
cout << "In VectorFileSensor " << filename << endl;

if (argCount == 3) {
labeled = StringUtils::toUInt32(args[2]);
labeled = toUInt32(args[2]);
} else {
// Check for some common extensions.
const char *csvExtensions[] = {".csv", ".CSV", nullptr};
Expand Down Expand Up @@ -263,17 +270,17 @@ std::string VectorFileSensor::executeCommand(const std::vector<std::string>& arg
string filename(args[1]);

if (argCount > 2) {
format = StringUtils::toUInt32(args[2]);
format = toUInt32(args[2]);
if ((format < 0) || (format > VectorFile::maxFormat()))
NTA_THROW << "VectorFileSensor: unknown file format '" << format << "'";
}

if (argCount > 3) {
begin = StringUtils::toUInt32(args[3]);
begin = toUInt32(args[3]);
}

if (argCount > 4) {
end = StringUtils::toUInt32(args[4]);
end = toUInt32(args[4]);
hasEnd = true;
}

Expand Down
Loading