Skip to content
This repository has been archived by the owner on Dec 25, 2023. It is now read-only.

Commit

Permalink
DLLs:
Browse files Browse the repository at this point in the history
- COMMON.CPP:
    - Changed strCase() function. Now apply changes on current string instead of create new ones and return it.
    - Added strTrim() function to remove all spaces from start and from the end of the current string (keep internal spaces).
    - Added strReplace() function to replace characters in current string.
- INPUT.DLL:
    - All functions that get input string as argument, clean string value with strUpr(), strTrim() and strReplace() (replace all inner spaces by '_' character).
- Recompile all DLLs.
  • Loading branch information
José Miguel Sánchez Fernández committed May 25, 2020
1 parent a12668d commit eead766
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 70 deletions.
50 changes: 41 additions & 9 deletions DLL/COMMON.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,50 @@

#include "common.h"

char* strCase(const char* input, const int mode)
void strCase(char* str, const int mode)
{
int len = strlen(input);
char* output = strAlloc(len);
if (str == NULL || strlen(str) == 0) return;

for(int i = 0; i < len; i++)
for(int i = 0; i < strlen(str); i++)
{
output[i] = mode ?
tolower(input[i]) :
toupper(input[i]);
str[i] = mode ? tolower(str[i]) : toupper(str[i]);
}
}

void strTrim(char* str)
{
if (str == NULL || strlen(str) == 0) return;

int s, e, i;

for (s = 0; s < strlen(str); s++)
{
if (str[s] != ' ') break;
}

for (e = strlen(str) - 1; e >= 0; e--)
{
if (str[e] != ' ')
{
e++;
break;
}
}

for (i = 0; s < e; i++, s++)
{
str[i] = str[s];
}
output[len] = '\0';

return output;
str[i] = '\0';
}

void strReplace(char * str, const char o, const char n)
{
if (str == NULL || strlen(str) == 0) return;

for (int i = 0; i < strlen(str); i++)
{
if (str[i] == o) str[i] = n;
}
}
6 changes: 4 additions & 2 deletions DLL/COMMON.H
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#define _isClamped(x, a, b) x >= a && x <= b

// Gets the string parameter from DIV call:
#define getStringParm(offset) (char*)&mem[text_offset + offset]
#define getStrParm() (char*)&mem[text_offset + getparm()]
// Allocate string pointer in div memory:
#define strAlloc(len) (char*)div_malloc(len + 1)
// Convert string to upper case:
Expand All @@ -37,6 +37,8 @@
#define strLwr(s) strCase(s, 1)

// String functions:
char* strCase(const char* input, const int mode);
void strCase(char* str, const int mode);
void strTrim(char* str);
void strReplace(char * str, const char o, const char n);

#endif
Binary file modified DLL/INPUT.DLL
Binary file not shown.
Loading

0 comments on commit eead766

Please sign in to comment.