1 // Copyright (C) 2018. Huawei Technologies Co., Ltd. All rights reserved. 2 3 #include <string.h> 4 #include <string> 5 #include "gtest/hwext/gtest-utils.h" 6 7 namespace testing { 8 9 /* 10 * Function: compareStringsByIgnoreCase 11 * Description: Ignore case to compare two strings 12 * Input: one: first string 13 * two: second string 14 * Output: N/A 15 * Return: true(equal),flase(not equal) 16 * Others: N/A 17 */ compareStringsByIgnoreCase(const char * one,const char * two)18 bool compareStringsByIgnoreCase(const char* one, const char* two) { 19 if (one == NULL && two == NULL) { 20 return true; 21 } 22 23 if (one == NULL || two == NULL) { 24 return false; 25 } 26 27 if (strcmp(one, two) == 0) { 28 return true; 29 } 30 31 const int len_one = strlen(one); 32 const int len_two = strlen(two); 33 34 if (len_one != len_two) { 35 return false; 36 } 37 38 if (len_one == 0 && len_two == 0) { 39 return true; 40 } 41 42 for (int i = 0; i < len_one; i++) { 43 if (tolower(one[i]) != tolower(two[i])) { 44 return false; 45 } 46 } 47 48 return true; 49 } 50 IsElementInVector(vector<int> vec,int element)51 bool IsElementInVector(vector<int> vec, int element){ 52 vector<int>::iterator it = find(vec.begin(), vec.end(), element); 53 if (it != vec.end()) { 54 return true; 55 } 56 return false; 57 } 58 SplitString(const string & str,const string & delim)59 vector<string> SplitString(const string& str, const string& delim) { 60 vector<string> result; 61 if (str != "") { 62 int len = str.length(); 63 char *src = new char[len + 1]; 64 memset(src, 0, len + 1); 65 strcpy(src, str.c_str()); 66 src[len] = '\0'; 67 68 char *tokenptr = strtok(src, delim.c_str()); 69 while (tokenptr != NULL) 70 { 71 string tk = tokenptr; 72 result.emplace_back(tk); 73 tokenptr = strtok(NULL, delim.c_str()); 74 } 75 delete[] src; 76 } 77 78 return result; 79 } 80 81 } // namespace testing 82