MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Case.cc File Reference
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>

Go to the source code of this file.

Functions

char * strtolower (char *str)
 Converts a string to all lower case. More...
 
char * strtoupper (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

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.

Definition at line 62 of file Case.cc.

References strtolower().

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
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

Definition at line 36 of file Case.cc.

References constants::i.

Referenced by strcicmp().

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:50
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

Definition at line 48 of file Case.cc.

References constants::i.

49 {
50  for (int i = 0; i < strlen(str); i++)
51  str[i] = toupper(str[i]);
52  return str;
53 }
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50