Skip to content
Snippets Groups Projects
Commit 47f34aae authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Make parse() a member function of struct atcode_format

Silly me, this is C++, do the C++ thing

No functional change.
parent c7c06373
No related branches found
No related tags found
No related merge requests found
...@@ -47,67 +47,65 @@ struct atcode_format { ...@@ -47,67 +47,65 @@ struct atcode_format {
bool thousep = false; // thousands-separated bool thousep = false; // thousands-separated
bool uppercase = false; bool uppercase = false;
bool width_specified = false; bool width_specified = false;
}; char* parse(char* sp) {
static char* parse_atcode_format(char* sp, struct atcode_format& fmt)
{
char* p; char* p;
fmt.disp_len=strlen(sp) + 2; disp_len=strlen(sp) + 2;
if((p = strchr(sp, '|')) != NULL) { if((p = strchr(sp, '|')) != NULL) {
if(strchr(p, 'T') != NULL) if(strchr(p, 'T') != NULL)
fmt.thousep = true; thousep = true;
if(strchr(p, 'U') != NULL) if(strchr(p, 'U') != NULL)
fmt.uppercase = true; uppercase = true;
if(strchr(p, 'L') != NULL) if(strchr(p, 'L') != NULL)
fmt.align = fmt.left; align = left;
else if(strchr(p, 'R') != NULL) else if(strchr(p, 'R') != NULL)
fmt.align = fmt.right; align = right;
else if(strchr(p, 'C') != NULL) else if(strchr(p, 'C') != NULL)
fmt.align = fmt.center; align = center;
else if(strchr(p, 'W') != NULL) else if(strchr(p, 'W') != NULL)
fmt.doubled = true; doubled = true;
else if(strchr(p, 'Z') != NULL) else if(strchr(p, 'Z') != NULL)
fmt.zero_padded = true; zero_padded = true;
else if(strchr(p, '>') != NULL) else if(strchr(p, '>') != NULL)
fmt.truncated = false; truncated = false;
} }
else if(strchr(sp, ':') != NULL) else if(strchr(sp, ':') != NULL)
p = NULL; p = NULL;
else if((p=strstr(sp,"-L"))!=NULL) else if((p=strstr(sp,"-L"))!=NULL)
fmt.align = fmt.left; align = left;
else if((p=strstr(sp,"-R"))!=NULL) else if((p=strstr(sp,"-R"))!=NULL)
fmt.align = fmt.right; align = right;
else if((p=strstr(sp,"-C"))!=NULL) else if((p=strstr(sp,"-C"))!=NULL)
fmt.align = fmt.center; align = center;
else if((p=strstr(sp,"-W"))!=NULL) /* wide */ else if((p=strstr(sp,"-W"))!=NULL) /* wide */
fmt.doubled=true; doubled=true;
else if((p=strstr(sp,"-Z"))!=NULL) else if((p=strstr(sp,"-Z"))!=NULL)
fmt.zero_padded=true; zero_padded=true;
else if((p=strstr(sp,"-T"))!=NULL) else if((p=strstr(sp,"-T"))!=NULL)
fmt.thousep=true; thousep=true;
else if((p=strstr(sp,"-U"))!=NULL) else if((p=strstr(sp,"-U"))!=NULL)
fmt.uppercase=true; uppercase=true;
else if((p=strstr(sp,"->"))!=NULL) /* wrap */ else if((p=strstr(sp,"->"))!=NULL) /* wrap */
fmt.truncated = false; truncated = false;
if(p!=NULL) { if(p!=NULL) {
char* lp = p; char* lp = p;
lp++; // skip the '|' or '-' lp++; // skip the '|' or '-'
while(*lp == '>'|| IS_ALPHA(*lp)) while(*lp == '>'|| IS_ALPHA(*lp))
lp++; lp++;
if(*lp) if(*lp)
fmt.width_specified = true; width_specified = true;
while(*lp && !IS_DIGIT(*lp)) while(*lp && !IS_DIGIT(*lp))
lp++; lp++;
if(*lp && IS_DIGIT(*lp)) { if(*lp && IS_DIGIT(*lp)) {
fmt.disp_len=atoi(lp); disp_len=atoi(lp);
fmt.width_specified = true; width_specified = true;
} }
*p=0; *p=0;
} }
return p; return p;
} }
};
/****************************************************************************/ /****************************************************************************/
/* Returns 0 if invalid @ code. Returns length of @ code if valid. */ /* Returns 0 if invalid @ code. Returns length of @ code if valid. */
...@@ -170,7 +168,7 @@ int sbbs_t::show_atcode(const char *instr, JSObject* obj) ...@@ -170,7 +168,7 @@ int sbbs_t::show_atcode(const char *instr, JSObject* obj)
return len; return len;
} }
p = parse_atcode_format(sp, fmt); p = fmt.parse(sp);
cp = atcode(sp, str2, sizeof(str2), &pmode, fmt.align == fmt.center, obj); cp = atcode(sp, str2, sizeof(str2), &pmode, fmt.align == fmt.center, obj);
if(cp==NULL) if(cp==NULL)
...@@ -248,7 +246,7 @@ const char* sbbs_t::formatted_atcode(const char* sp, char* str, size_t maxlen) ...@@ -248,7 +246,7 @@ const char* sbbs_t::formatted_atcode(const char* sp, char* str, size_t maxlen)
struct atcode_format fmt; struct atcode_format fmt;
SAFECOPY(tmp, sp); SAFECOPY(tmp, sp);
char* p = parse_atcode_format(tmp, fmt); char* p = fmt.parse(tmp);
const char* cp = atcode(tmp, buf, sizeof buf); const char* cp = atcode(tmp, buf, sizeof buf);
if(cp == nullptr) if(cp == nullptr)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment