Case.h File Reference

Go to the source code of this file.

Functions

charstrtolower (char *str)
 Converts a string to all lower case. More...
 
charstrtoupper (char *str)
 Converts a string to all upper case. More...
 
int strcicmp (const char *s1, const char *s2)
 Case-insensitive string comparison. More...
 

Function Documentation

◆ strcicmp()

int strcicmp ( const char s1,
const char s2 
)

Case-insensitive string comparison.

The original strings are not overwritten.

Parameters
[in]s1A C-string (char*)
[in]s2A C-string (char*)
Returns
As with strcmp, returns 0 if the strings are identical up to case, and otherwise 1.
63 {
64  char* t1 = (char*) calloc(strlen(s1) + 1, sizeof(char));
65  char* t2 = (char*) calloc(strlen(s2) + 1, sizeof(char));
66  strncpy(t1, s1, strlen(s1));
67  strncpy(t2, s2, strlen(s2));
68  strtolower(t1);
69  strtolower(t2);
70  int out = strcmp(t1, t2);
71  if (out != 0)
72  out = 1;
73 
74  free(t1);
75  free(t2);
76  return out;
77 }
char * strtolower(char *str)
Converts a string to all lower case.
Definition: Case.cc:36

References strtolower().

◆ strtolower()

char* strtolower ( char str)

Converts a string to all lower case.

The original string is overwritten.

Parameters
[in]strA C-string (char*), that will be overwritten.
Returns
str
37 {
38  for (int i = 0; i < strlen(str); i++)
39  str[i] = tolower(str[i]);
40  return str;
41 }
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51

References constants::i.

Referenced by strcicmp().

◆ strtoupper()

char* strtoupper ( char str)

Converts a string to all upper case.

The original string is overwritten.

Parameters
[in]strA C-string (char*), that will be overwritten.
Returns
str
49 {
50  for (int i = 0; i < strlen(str); i++)
51  str[i] = toupper(str[i]);
52  return str;
53 }

References constants::i.