Choco OS  V.0.16.9.0
Join to the chocolate world
oc_string.c
Go to the documentation of this file.
1 
26 #define _GNU_SOURCE
27 #include <oc_string.h>
28 #include <stdint.h>
29 
35 #define _________________________________________INTERFACE_SECTION__________________________________________________________________________
36 
37 void string_reverse( char * String )
38 {
39  uint32_t stringLength = strlen(String);
40  uint32_t leftIndex = 0;
41  uint32_t rightIndex = stringLength - 1;
42  uint32_t leftEndIndex = stringLength / 2;
43  char savedSign = 0;
44 
45  while(leftIndex < leftEndIndex)
46  {
47  savedSign = String[leftIndex];
48 
49  String[leftIndex] = String[rightIndex];
50  String[rightIndex] = savedSign;
51 
52  rightIndex--;
53  leftIndex++;
54  }
55 }
56 
57 void remove_in_string( char * String , uint32_t Index , uint32_t NumberOfCharacters )
58 {
59  uint32_t length = strlen(String);
60  uint32_t lengthAfterRemove = length - NumberOfCharacters;
61 
62  for(uint32_t i = Index ; i < length ; i++)
63  {
64  if(i < lengthAfterRemove)
65  {
66  String[i] = String[i+NumberOfCharacters];
67  }
68  else
69  {
70  String[i] = 0;
71  }
72  }
73 }
74 
75 uint32_t put_to_string( char * String , uint32_t Size , uint32_t Index , char C )
76 {
77  uint32_t length = strlen(String);
78  uint32_t lengthAfterPut = length + 1;
79  uint32_t maxStringLength= Size - 1;
80  if(Size > 1 && Index < maxStringLength)
81  {
82  if(lengthAfterPut > maxStringLength)
83  {
84  lengthAfterPut = maxStringLength;
85  }
86  for(uint32_t i = (lengthAfterPut - 1); i > Index ; i--)
87  {
88  String[i] = String[i-1];
89  }
90 
91  String[Index++] = C;
92  String[lengthAfterPut] = 0;
93  }
94  return Index;
95 }
96 
97 uint32_t string_backspace( char * String , uint32_t Index )
98 {
99  uint32_t length = strlen(String);
100  if(Index <= length && Index > 0)
101  {
102  Index--;
103  if(Index > 0 && String[Index] == '\r' && String[Index-1] == '\n')
104  {
105  Index--;
106  remove_in_string(String,Index,2);
107  }
108  else
109  {
110  remove_in_string(String,Index,1);
111  }
112  }
113 
114  return Index;
115 }
116 
117 bool string_contains( const char * String , const char * SubString , bool CaseSensitive )
118 {
119  if(CaseSensitive)
120  {
121  return strstr(String,SubString) != NULL;
122  }
123  else
124  {
125  return strcasestr(String,SubString) != NULL;
126  }
127 }
128 
129 bool string_contains_special_characters( const char * String)
130 {
131  bool contains = false;
132 
133  if(String != NULL)
134  {
135  uint32_t length = strlen(String);
136 
137  for(uint32_t i = 0 ; i < length ; i++)
138  {
139  if( (uint8_t)String[i] < (uint8_t)'0' ||
140  ( (uint8_t)String[i] > (uint8_t)'9' && (uint8_t)String[i] < (uint8_t)'A' ) ||
141  ( (uint8_t)String[i] > (uint8_t)'Z' && (uint8_t)String[i] < (uint8_t)'a' ) ||
142  ( (uint8_t)String[i] > (uint8_t)'z')
143  )
144  {
145  contains = true;
146  break;
147  }
148  }
149  }
150 
151  return contains;
152 }
153 
154 #undef _________________________________________INTERFACE_SECTION__________________________________________________________________________
The file with interface for string library.
#define NULL
pointer to a zero
Definition: oc_null.h:37