Skip to content

Commit

Permalink
utilize hard tabs instead of soft && sign off the DCO
Browse files Browse the repository at this point in the history
Signed Off: [email protected]
  • Loading branch information
shumin1027 committed May 12, 2020
1 parent dca62bb commit 50b3ec7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
66 changes: 33 additions & 33 deletions src/lsfeventsparser/strreplace.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,41 @@
#include <stdlib.h>

char *strreplace(char const *const original,
char const *const pattern, char const *const replacement) {
size_t const replen = strlen(replacement);
size_t const patlen = strlen(pattern);
size_t const orilen = strlen(original);
char const *const pattern, char const *const replacement) {
size_t const replen = strlen(replacement);
size_t const patlen = strlen(pattern);
size_t const orilen = strlen(original);

size_t patcnt = 0;
const char *oriptr;
const char *patloc;
size_t patcnt = 0;
const char *oriptr;
const char *patloc;

// find how many times the pattern occurs in the original string
for (oriptr = original; (patloc = strstr(oriptr, pattern)); oriptr = patloc + patlen) {
patcnt++;
}
// find how many times the pattern occurs in the original string
for (oriptr = original; (patloc = strstr(oriptr, pattern)); oriptr = patloc + patlen) {
patcnt++;
}

{
// allocate memory for the new string
size_t const retlen = orilen + patcnt * (replen - patlen);
char *const returned = (char *) malloc(sizeof(char) * (retlen + 1));
{
// allocate memory for the new string
size_t const retlen = orilen + patcnt * (replen - patlen);
char *const returned = (char *) malloc(sizeof(char) * (retlen + 1));

if (returned != NULL) {
// copy the original string,
// replacing all the instances of the pattern
char *retptr = returned;
for (oriptr = original; (patloc = strstr(oriptr, pattern)); oriptr = patloc + patlen) {
size_t const skplen = patloc - oriptr;
// copy the section until the occurence of the pattern
strncpy(retptr, oriptr, skplen);
retptr += skplen;
// copy the replacement
strncpy(retptr, replacement, replen);
retptr += replen;
}
// copy the rest of the string.
strcpy(retptr, oriptr);
}
return returned;
}
if (returned != NULL) {
// copy the original string,
// replacing all the instances of the pattern
char *retptr = returned;
for (oriptr = original; (patloc = strstr(oriptr, pattern)); oriptr = patloc + patlen) {
size_t const skplen = patloc - oriptr;
// copy the section until the occurence of the pattern
strncpy(retptr, oriptr, skplen);
retptr += skplen;
// copy the replacement
strncpy(retptr, replacement, replen);
retptr += replen;
}
// copy the rest of the string.
strcpy(retptr, oriptr);
}
return returned;
}
}
2 changes: 1 addition & 1 deletion src/lsfeventsparser/strreplace.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
//

char *strreplace(char const *const original,
char const *const pattern, char const *const replacement);
char const *const pattern, char const *const replacement);

0 comments on commit 50b3ec7

Please sign in to comment.