Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <algorithm>
- #include <functional>
- #include <cctype>
- #include <locale>
- #include "impala_udf.h"
- // trim left
- 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;
- }
- // trim from end
- 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;
- }
- // trim from both ends
- static inline std::string &trim(std::string &s) {
- return ltrim(rtrim(s));
- }
- // given
- StringVal StandardizeAddress(FunctionContext* context, const StringVal& address, const StringVal& fname)
- {
- if (address.is_null) return StringVal::null();
- //std::string original((const char *)address.ptr, address.len);
- std::string original(trim((std::string)address.ptr), address.len);
- std::string standardized("");
- istringstream iss(original);
- string word;
- while(iss >> word) {
- if(map.find(word) != map.end()) {
- standardized.append(map[word]);
- }
- else {
- standardized.append(word);
- }
- }
- return StringVal::CopyFrom(context,
- reinterpret_cast<const uint8_t*>(standardized.c_str()), standardized.size());
- }
Add Comment
Please, Sign In to add comment