src/hotspot/share/logging/logTag.cpp
changeset 49163 580bb0b85f63
parent 49015 a12c9536d8a6
equal deleted inserted replaced
49162:c200b4700aeb 49163:580bb0b85f63
    21  * questions.
    21  * questions.
    22  *
    22  *
    23  */
    23  */
    24 #include "precompiled.hpp"
    24 #include "precompiled.hpp"
    25 #include "logging/logTag.hpp"
    25 #include "logging/logTag.hpp"
       
    26 #include "utilities/stringUtils.hpp"
    26 #include "utilities/globalDefinitions.hpp"
    27 #include "utilities/globalDefinitions.hpp"
    27 #include "utilities/ostream.hpp"
    28 #include "utilities/ostream.hpp"
    28 #include "utilities/quickSort.hpp"
    29 #include "utilities/quickSort.hpp"
    29 
    30 
    30 const char* LogTag::_name[] = {
    31 const char* LogTag::_name[] = {
    39     if (strcasecmp(str, _name[i]) == 0) {
    40     if (strcasecmp(str, _name[i]) == 0) {
    40       return static_cast<LogTagType>(i);
    41       return static_cast<LogTagType>(i);
    41     }
    42     }
    42   }
    43   }
    43   return __NO_TAG;
    44   return __NO_TAG;
       
    45 }
       
    46 
       
    47 LogTagType LogTag::fuzzy_match(const char *str) {
       
    48   size_t len = strlen(str);
       
    49   LogTagType match = LogTag::__NO_TAG;
       
    50   double best = 0.5; // required similarity to be considered a match
       
    51   for (size_t i = 1; i < LogTag::Count; i++) {
       
    52     LogTagType tag = static_cast<LogTagType>(i);
       
    53     const char* tagname = LogTag::name(tag);
       
    54     double score = StringUtils::similarity(tagname, strlen(tagname), str, len);
       
    55     if (score >= best) {
       
    56       match = tag;
       
    57       best = score;
       
    58     }
       
    59   }
       
    60   return match;
    44 }
    61 }
    45 
    62 
    46 static int cmp_logtag(LogTagType a, LogTagType b) {
    63 static int cmp_logtag(LogTagType a, LogTagType b) {
    47   return strcmp(LogTag::name(a), LogTag::name(b));
    64   return strcmp(LogTag::name(a), LogTag::name(b));
    48 }
    65 }