Guest User

Untitled

a guest
May 27th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. #include <string>
  2. #include <algorithm>
  3. #include <functional>
  4. #include <cctype>
  5. #include <locale>
  6.  
  7. #include "impala_udf.h"
  8.  
  9. // trim left
  10. static inline std::string &ltrim(std::string &s) {
  11. s.erase(s.begin(), std::find_if(s.begin(), s.end(),
  12. std::not1(std::ptr_fun<int, int>(std::isspace))));
  13. return s;
  14. }
  15.  
  16. // trim from end
  17. static inline std::string &rtrim(std::string &s) {
  18. s.erase(std::find_if(s.rbegin(), s.rend(),
  19. std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
  20. return s;
  21. }
  22.  
  23. // trim from both ends
  24. static inline std::string &trim(std::string &s) {
  25. return ltrim(rtrim(s));
  26. }
  27.  
  28. // given
  29. StringVal StandardizeAddress(FunctionContext* context, const StringVal& address, const StringVal& fname)
  30. {
  31. if (address.is_null) return StringVal::null();
  32. //std::string original((const char *)address.ptr, address.len);
  33. std::string original(trim((std::string)address.ptr), address.len);
  34. std::string standardized("");
  35. istringstream iss(original);
  36.  
  37. string word;
  38. while(iss >> word) {
  39. if(map.find(word) != map.end()) {
  40. standardized.append(map[word]);
  41. }
  42. else {
  43. standardized.append(word);
  44. }
  45. }
  46. return StringVal::CopyFrom(context,
  47. reinterpret_cast<const uint8_t*>(standardized.c_str()), standardized.size());
  48.  
  49. }
Add Comment
Please, Sign In to add comment