Skip to content

Commit

Permalink
added trim method
Browse files Browse the repository at this point in the history
  • Loading branch information
jobinrjohnson committed May 3, 2019
1 parent 55f5a30 commit 294a4d8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
3 changes: 2 additions & 1 deletion QSim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ std::vector<std::string> explode(std::string const &s, char delim)

for (std::string token; std::getline(iss, token, delim);)
{
result.push_back(std::move(token));
result.push_back(std::move(trim(token)));
}

return result;
Expand Down Expand Up @@ -237,6 +237,7 @@ int read_cmd_line(char *filename)
while (fin)
{
getline(fin, line);
line = trim(line);
if (line[0] == '#' || line.empty())
{
++line_no;
Expand Down
4 changes: 4 additions & 0 deletions utils/include/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#ifndef UTILS_UTIL_H_
#define UTILS_UTIL_H_

#include <iostream>
#include <algorithm>

// LOG LEVELS
#define LOG_LEVEL_VERBOSE 0
#define LOG_LEVEL_INFO 1
Expand All @@ -19,5 +22,6 @@ extern int LOG_LEVEL;

extern void printdebug(unsigned short int, const char *);
extern char getLevel(unsigned short int);
extern std::string trim(const std::string &);

#endif /* UTILS_UTIL_H_ */
18 changes: 17 additions & 1 deletion utils/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

#include <util.h>
#include <iostream>

char getLevel(unsigned short int level)
{
Expand Down Expand Up @@ -47,3 +46,20 @@ void printdebug(unsigned short int level, const char *message)
std::cout << type << ": " << message << "\n";
// TODO add debugging options
}


std::string trim(const std::string &s)
{
auto start = s.begin();
while (start != s.end() && std::isspace(*start)) {
start++;
}

auto end = s.end();
do {
end--;
} while (std::distance(start, end) > 0 && std::isspace(*end));

return std::string(start, end + 1);
}

1 change: 1 addition & 0 deletions web/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@
<div class="p-5">
<textarea name="code" id="m_code" class="form-control c1" rows="20" placeholder="Code Here"># SAMPLE PROGRAMFOR COIN FLIP ALGORITHM
# CHANGE THIS CODE

QREG 1
H 0
MEASURE</textarea>
Expand Down

0 comments on commit 294a4d8

Please sign in to comment.