Advertisement
575

Untitled

575
Jun 5th, 2024
477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.51 KB | None | 0 0
  1. #ifndef INCLUDE_EXPRTK_HPP
  2. #define INCLUDE_EXPRTK_HPP
  3.  
  4.  
  5. #include <algorithm>
  6. #include <cassert>
  7. #include <cctype>
  8. #include <cmath>
  9. #include <cstdio>
  10. #include <cstdlib>
  11. #include <cstring>
  12. #include <deque>
  13. #include <functional>
  14. #include <iterator>
  15. #include <limits>
  16. #include <list>
  17. #include <map>
  18. #include <set>
  19. #include <stack>
  20. #include <stdexcept>
  21. #include <string>
  22. #include <utility>
  23. #include <vector>
  24.  
  25.  
  26. namespace exprtk
  27. {
  28.    #ifdef exprtk_enable_debugging
  29.      #define exprtk_debug(params) printf params
  30.    #else
  31.      #define exprtk_debug(params) (void)0
  32.    #endif
  33.  
  34.    #define exprtk_error_location             \
  35.    "exprtk.hpp:" + details::to_str(__LINE__) \
  36.  
  37.    #if __cplusplus >= 201103L
  38.       #define exprtk_override override
  39.       #define exprtk_final    final
  40.       #define exprtk_delete   = delete
  41.    #else
  42.       #define exprtk_override
  43.       #define exprtk_final
  44.       #define exprtk_delete
  45.    #endif
  46.  
  47.    #if __cplusplus >= 201603L
  48.       #define exprtk_fallthrough [[fallthrough]];
  49.    #else
  50.       #define exprtk_fallthrough
  51.    #endif
  52.  
  53.    namespace details
  54.    {
  55.       typedef char                   char_t;
  56.       typedef char_t*                char_ptr;
  57.       typedef char_t const*          char_cptr;
  58.       typedef unsigned char          uchar_t;
  59.       typedef uchar_t*               uchar_ptr;
  60.       typedef uchar_t const*         uchar_cptr;
  61.       typedef unsigned long long int _uint64_t;
  62.       typedef long long int          _int64_t;
  63.  
  64.       inline bool is_whitespace(const char_t c)
  65.       {
  66.          return (' '  == c) || ('\n' == c) ||
  67.                 ('\r' == c) || ('\t' == c) ||
  68.                 ('\b' == c) || ('\v' == c) ||
  69.                 ('\f' == c) ;
  70.       }
  71.  
  72.       inline bool is_operator_char(const char_t c)
  73.       {
  74.          return ('+' == c) || ('-' == c) ||
  75.                 ('*' == c) || ('/' == c) ||
  76.                 ('^' == c) || ('<' == c) ||
  77.                 ('>' == c) || ('=' == c) ||
  78.                 (',' == c) || ('!' == c) ||
  79.                 ('(' == c) || (')' == c) ||
  80.                 ('[' == c) || (']' == c) ||
  81.                 ('{' == c) || ('}' == c) ||
  82.                 ('%' == c) || (':' == c) ||
  83.                 ('?' == c) || ('&' == c) ||
  84.                 ('|' == c) || (';' == c) ;
  85.       }
  86.  
  87.       inline bool is_letter(const char_t c)
  88.       {
  89.          return (('a' <= c) && (c <= 'z')) ||
  90.                 (('A' <= c) && (c <= 'Z')) ;
  91.       }
  92.  
  93.       inline bool is_digit(const char_t c)
  94.       {
  95.          return ('0' <= c) && (c <= '9');
  96.       }
  97.  
  98.       inline bool is_letter_or_digit(const char_t c)
  99.       {
  100.          return is_letter(c) || is_digit(c);
  101.       }
  102.  
  103.       inline bool is_left_bracket(const char_t c)
  104.       {
  105.          return ('(' == c) || ('[' == c) || ('{' == c);
  106.       }
  107.  
  108.       inline bool is_right_bracket(const char_t c)
  109.       {
  110.          return (')' == c) || (']' == c) || ('}' == c);
  111.       }
  112.  
  113.       inline bool is_bracket(const char_t c)
  114.       {
  115.          return is_left_bracket(c) || is_right_bracket(c);
  116.       }
  117.  
  118.       inline bool is_sign(const char_t c)
  119.       {
  120.          return ('+' == c) || ('-' == c);
  121.       }
  122.  
  123.       inline bool is_invalid(const char_t c)
  124.       {
  125.          return !is_whitespace   (c) &&
  126.                 !is_operator_char(c) &&
  127.                 !is_letter       (c) &&
  128.                 !is_digit        (c) &&
  129.                 ('.'  != c)          &&
  130.                 ('_'  != c)          &&
  131.                 ('$'  != c)          &&
  132.                 ('~'  != c)          &&
  133.                 ('\'' != c);
  134.       }
  135.  
  136.       inline bool is_valid_string_char(const char_t c)
  137.       {
  138.          return std::isprint(static_cast<uchar_t>(c)) ||
  139.                 is_whitespace(c);
  140.       }
  141.  
  142.       #ifndef exprtk_disable_caseinsensitivity
  143.       inline void case_normalise(std::string& s)
  144.       {
  145.          for (std::size_t i = 0; i < s.size(); ++i)
  146.          {
  147.             s[i] = static_cast<std::string::value_type>(std::tolower(s[i]));
  148.          }
  149.       }
  150.  
  151.       inline bool imatch(const char_t c1, const char_t c2)
  152.       {
  153.          return std::tolower(c1) == std::tolower(c2);
  154.       }
  155.  
  156.       inline bool imatch(const std::string& s1, const std::string& s2)
  157.       {
  158.          if (s1.size() == s2.size())
  159.          {
  160.             for (std::size_t i = 0; i < s1.size(); ++i)
  161.             {
  162.                if (std::tolower(s1[i]) != std::tolower(s2[i]))
  163.                {
  164.                   return false;
  165.                }
  166.             }
  167.  
  168.             return true;
  169.          }
  170.  
  171.          return false;
  172.       }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement