explode / trim / get_num_length
- // -------------------------- utils.cpp -----------------------------//
- #include "utils.h"
- vector<string> &explode(const string &str, const char delimiter, vector<string> &elements) {
- stringstream ss(str);
- string item;
- while (getline(ss, item, delimiter))
- elements.push_back(item);
- return elements;
- }
- vector<string> explode(const string &str, const char delimiter) {
- vector<string> elements;
- return explode(str, delimiter, elements);
- }
- // -------------------------- utils.h -----------------------------//
- #ifndef __UTILS_H
- #define __UTILS_H
- #include <iostream>
- #include <stdio.h>
- #include <vector>
- #include <sstream>
- #include <string>
- #include <algorithm>
- using namespace std;
- vector<string> &explode(const string &str, const char delimiter, vector<string> &elements);
- vector<string> explode(const string &str, const char delimiter);
- static inline std::string <rim(std::string &s) {
- s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
- return s;
- }
- static inline std::string &rtrim(std::string &s) {
- s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
- return s;
- }
- static inline std::string &trim(std::string &s) {
- return ltrim(rtrim(s));
- }
- static inline unsigned long get_num_length(unsigned long num, unsigned long radix) {
- int length = 0;
- while (num) {
- num /= radix;
- length++;
- }
- return length;
- }
- #endif
Может кому-то приходятся.