&FUN_CAPSTR_ALL Global Utility Functions=
iter(
%0,
capstr(##),
switch(%1,,%B,%1),
switch(%1,,%B,%1))
&FUNHELP_CAPSTR_ALL Global Utility Functions=
This function will capitalize each word of a multi-word string.
It defaults to a space-delimited string but you can pass a
delimiter if you want.%R%R
Usage: capstr_all(<string>,\[delimiter\])
#define LOWER© ((©>='A' && © <= 'Z') ? (©+('a'-'A')) : ©)
#define UPPER© ((©>='a' && © <= 'z') ? (©+('A'-'a')) : ©)
/*
* str_cew: Function to capitalize the first letter each word in a string.
* All other letters in the string are returned returned in lower case.
* Returns: New string with each word capitalized, or NULL if fails.[s].
*
* Does not modify original string.
* If you wish to modify the original string, simply assign the new value back to it:
* string = char *strn_cew(string);
*/
char *str_cew(char *argument)
{
char first_arg[MAX_STRING_LENGTH];
if (!argument) {
log("SYSERR: str_cew received a NULL pointer!");
*first_arg = '\0';
return (NULL);
}
/* CircleMUD function to strip leading spaces from the string */
skip_spaces(&argument);
first_arg = '\0';
*first_arg = UPPER(*argument);
argument++;
while (*argument) {
if (isspace(*argument)) {
*(first_arg++) = *argument;
argument++;
*(first_arg++) = UPPER(*argument);
} else {
*(first_arg++) = LOWER(*argument);
}
argument++;
}
return (first_arg);
}
ACMD(do_immtest)
{
char buf[MAX_STRING_LENGTH];
str_cew(argument, buf);
send_to_char(ch, "str_cew output: %s\r\n", buf);
}
void str_cew(char *argument, char *new_arg);
/*
* str_cew: Function to capitalize the first letter each word in a string.
* All other letters in the string are returned returned in lower case.
*
* Does not modify original string. Returns void.
*/
void str_cew(char *argument, char *new_arg)
{
if (!argument || !*argument) {
log("SYSERR: str_cew received a NULL pointer!");
*new_arg = '\0';
return;
}
if (argument == '\0') {
log("SYSERR: str_cew received no argument!");
*new_arg = '\0';
return;
}
/* CircleMUD function to strip leading spaces from the string */
skip_spaces(&argument);
*(new_arg++) = UPPER(*argument);
argument++;
while (*argument) {
if (isspace(*argument)) {
*(new_arg++) = LOWER(*argument);
argument++;
if (*argument != '\0')
*(new_arg++) = UPPER(*argument);
} else {
*(new_arg++) = LOWER(*argument);
}
if (*argument != '\0')
argument++;
}
*new_arg = '\0';
return;
}
/*
* str_cew: Function to capitalize the first letter each word in a string.
* All other letters in the string are returned returned in lower case.
* Does not modify original string. Returns void.
*
* Written by Ulath of Caer Dubrin 12 July 2010
* Feature and Bugfix suggestions Jamdog of tbaMUD forums 13 July 2010
*/
void str_cew(char *argument, char *new_arg)
{
*new_arg = '\x0';
if (!argument || !new_arg) {
log("SYSERR: str_cew received a NULL pointer!");
return;
}
if (!*argument) {
log("SYSERR: str_cew received no argument!");
return;
}
/* CircleMUD function to strip leading spaces from the string */
skip_spaces(&argument);
*(new_arg++) = UPPER(*argument);
argument++;
while (*argument) {
if (isspace(*argument)) {
while (*argument && isspace(*argument)) { /* Loop here, so we can work with multiple spaces. Thanks Jamdog */
*(new_arg++) = *argument; /* Since this is a space, we don't need to use LOWER on it. Thanks Jamdog. */
argument++;
}
if (*argument != '\x0') {
*(new_arg++) = UPPER(*argument);
}
} else {
*(new_arg++) = LOWER(*argument);
}
if (*argument != '\x0')
argument++;
}
*new_arg = '\x0';
return;
}
{"CAPSTRALL", fun_capstrall, 1, 1, 1, 0, CA_PUBLIC},
static FUNCTION(fun_capstrall)
{
UNUSED_PARAMETER(executor);
UNUSED_PARAMETER(caller);
UNUSED_PARAMETER(enactor);
UNUSED_PARAMETER(nfargs);
UNUSED_PARAMETER(cargs);
UNUSED_PARAMETER(ncargs);
char *pString = fargs[0];
char *pBuffer = *bufc;
size_t nString = strlen(pString);
nString = safe_copy_buf(pString, nString, buff, bufc);
bool findblank = false;
// Find the first text character in (nString, pBuffer).
//
while (nString)
{
size_t nTokenLength0;
size_t nTokenLength1;
int iType = ANSI_lex(nString, pBuffer, &nTokenLength0, &nTokenLength1);
if (iType == TOKEN_TEXT_ANSI)
{
if (!findblank) {
*pBuffer = mux_toupper(*pBuffer);
findblank = true;
} else if (*pBuffer == ' ')
findblank = false;
}
pBuffer += nTokenLength0;
nString -= nTokenLength0;
}
}
#include <iostream>
#include <cstring>
#include <cctype>
using namespace std;
void cap_all_str( char *s )
{
size_t nchars = strlen(s);
bool findblank = false;
while (nchars) {
if (!findblank) {
*s = toupper(*s);
findblank = true;
} else if (*s == ' ')
findblank = false;
++s;
–nchars;
}
return;
}
int main(void) {
char test[] = "these are the times that try men's souls";
cout << test << endl;
cap_all_str(test);
cout << test << endl;
return 0;
}
#include <iostream>
#include <cstring>
#include <cctype>
using namespace std;
void cap_all_str(char *s)
{
bool skipping_blank = true;
while (*s) {
if (skipping_blank && *s != ' ') {
skipping_blank = false;
*s = toupper(*s);
}
else if (*s == ' ') {
skipping_blank = true;
}
s++;
}
return;
}
int main()
{
char test[] = " these are the times that try men's souls";
cout << test << endl;
cap_all_str(test);
cout << test << endl;
return 0;
}
$ g++ test.cpp
$ ./a.out
these are the times that try men's souls
These Are The Times That Try Men's Souls
$
#include <iostream>
#include <cstring>
#include <cctype>
using namespace std;
void cap_all_str( char *s )
{
size_t nchars = strlen(s);
bool findblank = false;
while (nchars) {
if (!findblank && !isspace(*s)) {
*s = toupper(*s);
findblank = true;
} else if (isspace(*s))
findblank = false;
++s;
–nchars;
}
return;
}
int main(void) {
char t1[] = "these are the times that try men's souls";
cout << t1 << endl;
cap_all_str(t1);
cout << t1 << endl;
char t2[] = " it was a pleasure to\tburn, \n\rto see things blackened and changed. ";
cout << t2 << endl;
cap_all_str(t2);
cout << t2 << endl;
return 0;
}
[setq(0,lcstr(sort(lattr(%#/strengths_*))))][iter(%q0,[ljust(edit(capstr(mid(##,strlen(strengths_),strlen(##))),-,%b),24)][switch(mod(#@,3),0,%r%b)])]
Any assistance would be appreciated.