Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "CS_Str.h"
- #include <iostream>
- //Constructer
- CS_Str::CS_Str()
- {
- char * nChar = nullptr;
- char * filler = nullptr;
- }
- // destructor
- CS_Str::~CS_Str()
- {
- if (nChar != nullptr)
- {
- delete nChar;
- }
- else
- {
- }
- if (filler != nullptr)
- {
- delete[] filler;
- }
- else
- {
- }
- filler = nChar = nullptr;
- }
- // string constructor
- CS_Str::CS_Str(char *nString)
- {
- char* string1 = new char[strlen(nString)+1];
- string1 = nString;
- }
- //FUNCTION strlen(string)
- //SET character_index to 0
- //WHILE string[character_index] != 0
- //character_index++
- //ENDWHILE
- //RETURN character_index
- //ENDFUNCTION
- int CS_Str::CS_strlen(char* nString)
- {
- if(nString == nullptr)
- {
- return -42;
- }
- int char_index = 0;
- while (nString[char_index] != 0)
- {
- char_index++;
- }
- return char_index;
- }
- //FUNCTION strcpy(destination, source)
- //SET destination_index to strlen(destination) + 1
- //SET source_index to 0
- //WHILE source[source_index] != 0
- //SET destination[destination_index] to source[source_index]
- //++destination_index
- //++source_index
- //ENDWHILE
- //SET destination[destination_index] to 0
- //RETURN destination
- //ENDFUNCTION
- char CS_Str::CS_strcat(char *nString, char *wString)
- {
- if (nString == nullptr)
- {
- return -42;
- }
- else if (wString == nullptr)
- {
- return -43;
- }
- int wString_index = CS_strlen(wString) + 1;
- int nString_index = 0;
- while (nString[nString_index] != NULL)
- {
- wString[wString_index] = nString[nString_index];
- ++wString_index;
- ++nString_index;
- }
- wString[wString_index] = 0;
- return *nString;
- }
- // String prepend, reverse append
- char CS_Str::CS_strpre(char *nString, char *wString)
- {
- if (nString == nullptr)
- {
- return -44;
- }
- else if (wString == nullptr)
- {
- return -45;
- }
- int wString_index = CS_strlen(wString) + 1;
- int nString_index = 0;
- while (wString[wString_index] != NULL)
- {
- nString[nString_index] = wString[wString_index];
- ++wString_index;
- ++nString_index;
- }
- wString[wString_index] = 0;
- return *nString;
- }
- //FUNCTION strcmp(string1, string2)
- //SET character_index to 0
- //SET result to 0
- //SET running to true
- //WHILE running
- //IF string1[character_index] == 0 AND string2[character_index] == 0 THEN
- //SET result to 0
- //BREAK
- //ELSEIF string1[character_index] > string2[character_index] THEN
- //SET result to 1
- //BREAK
- //ELSE IF string1[character_index] < string2[character_index] THEN
- //SET result to - 1
- //BREAK
- //ELSE
- //++character_index
- //ENDIF
- //ENDWHILE
- //RETURN result
- //ENDFUNCTION
- int CS_Str::CS_strcmp(char* nString, char* wString)
- {
- if (nString == nullptr)
- {
- return -42;
- }
- else if (wString == nullptr)
- {
- return -43;
- }
- int char_index = 0, result = 0;
- bool running = true;
- while (running = true)
- {
- if (nString[char_index] == 0 && wString[char_index] == 0)
- {
- result = 0;
- break;
- }
- else if (nString[char_index] > wString[char_index])
- {
- result = 1;
- break;
- }
- else if (nString[char_index] < wString[char_index])
- {
- result = -1;
- break;
- }
- else
- {
- ++char_index;
- }
- }
- return result;
- }
- //FUNCTION strcpy(destination, source)
- //SET character_index to 0
- //WHILE source[character_index] != 0
- //SET destination[character_index] to source[character_index]
- //++character_index
- //ENDWHILE
- //SET destination[character_index] to 0
- //RETURN destination
- //ENDFUNCTION
- char CS_Str::CS_strcpy(char *nString, char *wString)
- {
- if (nString == nullptr)
- {
- return -42;
- }
- else if (wString == nullptr)
- {
- return -43;
- }
- int char_index = 0;
- while (nString[char_index] != 0)
- {
- wString[char_index] = nString[char_index];
- ++char_index;
- }
- wString[char_index] = 0;
- return *wString;
- }
- //6. Write a function for each of the following descriptions.For each function, use the pointer
- //notation ONLY.Do NOT use the array index[] notation.
- //A.Write a function RevString(char* array) which reverses array.The function
- //returns nothing.
- //B.Write a function CountEven(int* array, int array_len) which receives an
- //integer array and its size, and returns the number of even numbers in the array.
- //C.Write a function Maximum(double* array, int array_size) that returns a
- //pointer to the maximum value of an array of doubles.If the array is empty, return
- //nullptr.
- //D.Write a function Contains(char* array, char search_value) which returns
- //true if the 1st parameter contains the 2nd parameter, or false otherwise.
- //Upper
- char CS_Str::CS_strupper(char *nString)
- {
- if (nString == nullptr)
- {
- return -42;
- }
- int len = CS_strlen(nString);
- filler = new char[len + 1];
- for(int i = 0; i != len; i++)
- {
- if (filler[i] >= 95)
- {
- filler[i] = (nString[i] - 32);
- }
- else if ((nString[i] < 95))
- {
- filler[i] = nString[i] ;
- }
- else
- {
- return -47;
- }
- }
- return *filler;
- }
- //Lower
- char CS_Str::CS_strlower(char *nString)
- {
- if (nString == nullptr)
- {
- return -42;
- }
- int len = CS_strlen(nString);
- filler = new char[len+1];
- for (int i = 0; i <= len; i++ )
- {
- if (nString[i] >= 95)
- {
- filler[i] = nString[i] ; // 204???
- }
- else if((int)nString[i] <= 95)
- {
- filler[i] = ((int)nString[i] + 32); //40?? low upper, high lower ASCHII
- }
- else
- {
- return -44;
- }
- }
- return *filler;
- }
- //sub string index
- //substring
- //replace substring
- //input c style??
- //char index
- char CS_Str::CS_charIndex(char *nString, int index)
- {
- if (nString == nullptr)
- {
- return 42;
- }
- else if (index > CS_strlen(nString))
- {
- return 35;
- }
- nChar = new char;
- *nChar = nString[index-1];
- return *nChar;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement