Exemplo n.º 1
0
/* find a substring within a specified length string with a case 
 * insensitive search
 */
PUBLIC char *
strncasestr (const char * str, const char * substr, int32 len)
{
	register int count=0;
	register int count2=0;
    register const char *pA;
    register const char *pB;
    register const char *pC;
	uint8 *toupper_table = xp_get_toupper_table();

    if(!str || !substr)
        return(NULL);
   
    for(pA=str; count < len; pA++, count++)
      {
        if(XP_STR_TOUPPER(*pA) == XP_STR_TOUPPER(*substr))
          {
            for(pB=pA, pC=substr, count2=count; count2<len; 
													count2++,pB++,pC++)
              {
                if(!(*pC))
                    return((char *)pA);

                if(!(*pB))
                    break;

                if(XP_TO_UPPER(*pB) != XP_TO_UPPER(*pC))
                    break;
              }
          }
      }

    return(NULL);
}
Exemplo n.º 2
0
/* CSS_ConvertToJSCompatibleName
 * converts characters which are illegal in JavaScript names.
 *
 *  Anne-Marie ==> Anne_Marie     "-" (dash) always converts to "_"
 *  5NewportRd ==> _5NewportRd    1st character a digit prepend "_"
 *  Convert lower to upper case when second parameter is true.
 *  When second parameter is false, prepend "_" to reserved words.
 * Returns NULL on error.
 */
PUBLIC char *
CSS_ConvertToJSCompatibleName(char *css_name, XP_Bool uppercase_it)
{
	int32 len;
	char *new_name;
	char *cp;
        XP_Bool reserved = 0;

	XP_ASSERT(css_name);

	if (!css_name)
		return NULL;

	len = XP_STRLEN(css_name);
        if (! uppercase_it)
            reserved = IsReservedWord(css_name);
	if (reserved || XP_IS_DIGIT(*css_name))
		len++;

	cp = new_name = XP_ALLOC((len+1) * sizeof(char));
	if (!new_name)
		return NULL;

	if (reserved || XP_IS_DIGIT(*css_name)) {
		*cp = '_';
		cp++;
	}

	for(; *css_name; css_name++, cp++)
		if (*css_name == '-')
            *cp = '_';
        else 
            *cp = uppercase_it ? (XP_TO_UPPER(*css_name)) : *css_name;

	*cp = '\0';

	return new_name;
}