Ejemplo n.º 1
0
std::string Team::getName() const {
  if (superheroes.size() == 0) 
    return "";
  std::string answer;
  std::list<Superhero>::const_iterator itr;
  for (itr = superheroes.begin(); itr != superheroes.end(); itr++) {
    char first_consonant = ' ';
    char first_vowel = ' ';
    std::string true_identity = itr->getTrueIdentity();
    for (int j = 0; j < true_identity.size(); j++) {
      if (first_consonant == ' ' && isconsonant(true_identity[j]))
        first_consonant = tolower(true_identity[j]);
      if (first_vowel == ' ' && isvowel(true_identity[j]))
        first_vowel = tolower(true_identity[j]);
    }
    answer.push_back(first_consonant);
    answer.push_back(first_vowel);
  }

  answer[0] = toupper(answer[0]);
  return answer;
}
Ejemplo n.º 2
0
static int
rightmatch(char *pattern,	/* first char of pattern to match in text */
	   char *context)	/* last char of text to be matched */
{
  char *pat;
  char *text;

  if (*pattern == '\0')		/* null string matches any context */
    return TRUE;

  pat = pattern;
  text = context;

  for (pat = pattern; *pat != '\0'; pat++)
    {
      /* First check for simple text or space */
      if (isalpha((int)(*pat)) || *pat == '\'' || *pat == ' ')
	if (*pat != *text)
	  return FALSE;
	else
	  {
	    text++;
	    continue;
	  }

      switch (*pat)
	{
	case '#':		/* One or more vowels */
	  if (!isvowel(*text))
	    return FALSE;

	  text++;

	  while (isvowel(*text))
	    text++;
	  break;

	case ':':		/* Zero or more consonants */
	  while (isconsonant(*text))
	    text++;
	  break;

	case '^':		/* One consonant */
	  if (!isconsonant(*text))
	    return FALSE;
	  text++;
	  break;

	case '.':		/* B, D, V, G, J, L, M, N, R, W, Z */
	  if (*text != 'B' && *text != 'D' && *text != 'V'
	      && *text != 'G' && *text != 'J' && *text != 'L'
	      && *text != 'M' && *text != 'N' && *text != 'R'
	      && *text != 'W' && *text != 'Z')
	    return FALSE;
	  text++;
	  break;

	case '+':		/* E, I or Y (front vowel) */
	  if (*text != 'E' && *text != 'I' && *text != 'Y')
	    return FALSE;
	  text++;
	  break;

	case '%':		/* ER, E, ES, ED, ING, ELY (a suffix) */
	  if (*text == 'E')
	    {
	      text++;
	      if (*text == 'L')
		{
		  text++;
		  if (*text == 'Y')
		    {
		      text++;
		      break;
		    }
		  else
		    {
		      text--;	/* Don't gobble L */
		      break;
		    }
		}
	      else
		if (*text == 'R' || *text == 'S' 
		    || *text == 'D')
		  text++;
	      break;
	    }
	  else
	    if (*text == 'I')
	      {
		text++;
		if (*text == 'N')
		  {
		    text++;
		    if (*text == 'G')
		      {
			text++;
			break;
		      }
		  }
		return FALSE;
	      }
	    else
	      return FALSE;

	default:
	  fprintf(stderr, "Bad char in right rule:'%c'\n", *pat);
	  return FALSE;
	}
    }

  return TRUE;
}
Ejemplo n.º 3
0
static int
leftmatch(char *pattern,	/* first char of pattern to match in text */
	  char *context)	/* last char of text to be matched */
{
  char *pat;
  char *text;
  int count;

  if (*pattern == '\0')		/* null string matches any context */
    {
      return TRUE;
    }

  /* point to last character in pattern string */
  count = strlen(pattern);
  pat = pattern + (count - 1);

  text = context;

  for (; count > 0; pat--, count--)
    {
      /* First check for simple text or space */
      if (isalpha((int)(*pat)) || *pat == '\'' || *pat == ' ')
	if (*pat != *text)
	  return FALSE;
	else
	  {
	    text--;
	    continue;
	  }

      switch (*pat)
	{
	case '#':		/* One or more vowels */
	  if (!isvowel(*text))
	    return FALSE;

	  text--;

	  while (isvowel(*text))
	    text--;
	  break;

	case ':':		/* Zero or more consonants */
	  while (isconsonant(*text))
	    text--;
	  break;

	case '^':		/* One consonant */
	  if (!isconsonant(*text))
	    return FALSE;
	  text--;
	  break;

	case '.':		/* B, D, V, G, J, L, M, N, R, W, Z */
	  if (*text != 'B' && *text != 'D' && *text != 'V'
	      && *text != 'G' && *text != 'J' && *text != 'L'
	      && *text != 'M' && *text != 'N' && *text != 'R'
	      && *text != 'W' && *text != 'Z')
	    return FALSE;
	  text--;
	  break;

	case '+':		/* E, I or Y (front vowel) */
	  if (*text != 'E' && *text != 'I' && *text != 'Y')
	    return FALSE;
	  text--;
	  break;

	case '%':
	default:
	  fprintf(stderr, "Bad char in left rule: '%c'\n", *pat);
	  return FALSE;
	}
    }

  return TRUE;
}
Ejemplo n.º 4
0
Archivo: text.c Proyecto: EQ4/rsynth
static int
leftmatch(unsigned char *pattern, unsigned char *context)
                                           /* first char of pattern to match in text */
                                           /* last char of text to be matched */
{
 unsigned char *pat;
 unsigned char *text;
 int count;
 if (*pattern == '\0')
  /* null string matches any context */
  {
   return TRUE;
  }

 /* point to last character in pattern string */
 count = strlen((char *) pattern);
 pat = pattern + (count - 1);
 text = context;
 for (; count > 0; pat--, count--)
  {
   /* First check for simple text or space */
   if (isalpha(*pat & 0xFF) || *pat == '\'' || *pat == ' ')
    {
     if (*pat != *text)
      return FALSE;
     else
      {
       text--;
       continue;
      }
    }
   switch (*pat)
    {
     case '#':                   /* One or more vowels */
      if (!isvowel(*text,0))
       return FALSE;
      text--;
      while (isvowel(*text,0))
       text--;
      break;      

     case ':':                   /* Zero or more consonants */
      while (isconsonant(*text))
       text--;
      break;

     case '^':                   /* One consonant */
      if (!isconsonant(*text))
       return FALSE;
      text--;
      break;

     case '$':                   /* duplicate consonant jms */
      if (!isconsonant(*text))
       return FALSE;
      if (*text != *(text - 1))
       return FALSE;
      text--;
      text--;
      break;

     case '.':                   /* B, D, V, G, J, L, M, N, R, W, Z */
      if (*text != 'b' && *text != 'd' && *text != 'v'
          && *text != 'g' && *text != 'j' && *text != 'l'
          && *text != 'm' && *text != 'n' && *text != 'r'
          && *text != 'w' && *text != 'z')
       return FALSE;
      text--;
      break;

     case '+':                   /* E, I or Y (front vowel) */
      if (*text != 'e' && *text != 'i' && *text != 'y')
       return FALSE;
      text--;
      break;  

     case '%':
     default:
      fprintf(stderr, "Bad char in left rule: '%c'\n", *pat);
      return FALSE;
    }
  }
 return TRUE;
}
Ejemplo n.º 5
0
Archivo: text.c Proyecto: EQ4/rsynth
static int
rightmatch(unsigned char *pattern, unsigned char *context)
                                           /* first char of pattern to match in text */
                                           /* last char of text to be matched */
{
 unsigned char *pat;
 unsigned char *text;
 if (*pattern == '\0')
  /* null string matches any context */
  return TRUE;
 pat = pattern;
 text = context;
 for (pat = pattern; *pat != '\0'; pat++)
  {
   /* First check for simple text or space */
   if (isalpha(*pat & 0xFF) || *pat == '\'' || *pat == ' ')
    {
     if (*pat != *text)
      return FALSE;
     else
      {
       text++;
       continue;
      }
    }
   switch (*pat)
    {
     case '#':                   /* One or more vowels */
      if (!isvowel(*text,0))
       return FALSE;
      text++;
      while (isvowel(*text,0))
       text++;
      break;

     case '=':                   /* Terminal, optional 's' */
      if (*text == 's' && text[1] == ' ')
       text++;
      if (*text != ' ')
       return FALSE;
      text++; 
      break;

     case ':':                   /* Zero or more consonants */
      while (isconsonant(*text))
       text++;
      break;

     case '^':                   /* One consonant */
      if (!isconsonant(*text))
       return FALSE;
      text++;
      break;

     case '$':                   /* duplicate consonant jms */
      if (!isconsonant(*text))
       return FALSE;
      if (*text != *(text + 1))
       return FALSE;
      text++;
      text++;
      break;

     case '.':                   /* B, D, V, G, J, L, M, N, R, W, Z */
      if (*text != 'b' && *text != 'd' && *text != 'v'
          && *text != 'g' && *text != 'j' && *text != 'l'
          && *text != 'm' && *text != 'n' && *text != 'r'
          && *text != 'w' && *text != 'z')
       return FALSE;
      text++;
      break;

     case '+':                   /* E, I or Y (front vowel) */
      if (*text != 'e' && *text != 'i' && *text != 'y')
       return FALSE;
      text++;
      break;

     case '%':                   /* ER, E, ES, ED, ING, ELY (a suffix) */
      if (*text == 'e')
       {
        text++;
        if (*text == 'l')
         {
          text++;
          if (*text == 'y')
           {
            text++;
            break;
           }
          else
           {
            text--;               /* Don't gobble L */
            break;
           }
         }
        else if (*text == 'r' || *text == 's' || *text == 'd')
         text++;
        break;
       }
      else if (*text == 'i')
       {
        text++;
        if (*text == 'n')
         {
          text++;
          if (*text == 'g')
           {
            text++;
            break;
           }
         }
        return FALSE;
       }
      else
       return FALSE;
     default:
      fprintf(stderr, "Bad char in right rule:'%c'\n", *pat);
      return FALSE;
    }
  }
 return TRUE;
}
Ejemplo n.º 6
0
bool BuffDoc::getline(CDrawBuffer* buff, int wth, unsigned short _lborder, unsigned short _rborder, bool hyphenate, int availht)
{
    bool moreleft = true;
    bool margindone = false;
    int isCentred = -1;
    int w = wth-(_lborder+_rborder);
    tchar ch = 32;
    CStyle cs;
    buff->empty();
    if (exp == NULL)
    {
	buff->empty();
	buff->setEof();
	return false;
    }
    int len = 0;
    if (lastword.length() > 0)
    {
	if (isCentred < 0)
	  {
	    isCentred = (lastword.firststyle().getJustify() == m_AlignCentre) ? 1 : 0;
	  }
	*buff = lastword;
	cs = lastword.laststyle();
	w -= buff->leftMargin() + buff->rightMargin();
	margindone = true;
	len = lastword.length();
    }
    else buff->empty();
    lastword.empty();
    unsigned int slen = buff->width(availht, len);
    if (lastispara) buff->setstartpara();
    int nospaces = 0;
    while (1)
    {
	getch(ch, cs, lastsizes[len]);
	if (isCentred < 0)
	  {
	    isCentred = (cs.getJustify() == m_AlignCentre) ? 1 : 0;
	  }
	if (ch == 10 && len == 0 && !lastispara)
	{
	    getch(ch, cs, lastsizes[len]);
	    buff->setstartpara();
	}
	if (ch == UEOF)
	{
	    buff->setendpara(cs);
	    if (len == 0)
	    {
		buff->setEof();
		moreleft = false;
	    }
	    laststartline = exp->locate();
	    break;
	}
	if (ch == 10)
	{
	    buff->setendpara(cs);
	    lastispara = true;
	    laststartline = exp->locate();
	    break;
	}
	if (ch == 6)
	{
	    buff->setendpara(cs);
	    buff->setBop();
	    lastispara = true;
	    laststartline = exp->locate();
	    break;
	}
	lastispara = false;
	buff->addch(ch, cs);
	if (ch == ' ')
	  {
	    nospaces++;
	  }
	len++;
	if (!margindone)
	{
	    w -= buff->leftMargin() + buff->rightMargin();
	    margindone = true;
	}
#ifdef INCREMENTALWIDTH
  	if ((slen += buff->charwidth(len-1, cs)) > w)
#else
  	if ((slen = buff->width(availht, len)) > w)
#endif
	{
	    if (ch == ' ' || len == 1)
	    {
		if (ch == ' ') buff->truncate(len-1);
		laststartline = exp->locate();
		break;
	    }
	    else // should do a backward search for spaces, first.
	    {
	      int lastk = len-4;
		for (int i = len-2; i > 0; i--)
		{
		    if (
			(((*buff)[i] == 0x2014) && isletter((*buff)[i+1]))
			||
			((*buff)[i] == '-')
			//			((*buff)[i] == '-' && !(((*buff)[i-1] == '-') || ((*buff)[i+1] == '-')))
)
		    {
			(*buff)[len] = 0;
			lastword.setright(*buff, i+1);
			buff->truncate(i+1);
			(*buff)[i+1] = '\0';
			laststartline = lastsizes[i+1];
			//			buff->resize();
			for (int j = 0; j < lastword.length(); j++)
			{
			    lastsizes[j] = lastsizes[j+i+1];
			}
			return true;
		    }

		    //if (hyphenate && (m_hyphenthreshold+1)*i < m_hyphenthreshold*len)
		    // We end up with i+1 characters instead of len-1
		    // Thus we are removing len - 1 - (i + 1) = len-i-2
		    // The space characters will be stretched to cover
		    // nospaces to nospaces + len - i - 2
		    // The stretch factor is hence
		    // (nospaces+len-i-2)/nospaces
		    if (hyphenate && !isCentred && ( 100*(nospaces+len-i-2) > (100+m_hyphenthreshold)*nospaces ))
		      {
			/*
			if (m_customhyphen)
			  {
			    for (int k = lastk; k >= i && k >= 2; k--)
			      {
				if (
				    isletter((*buff)[k+3])
				    &&
				    isletter((*buff)[k+2])
				    &&
				    isvowel((*buff)[k+1])
				    &&
				    isconsonant((*buff)[k])
				    &&
				    isletter((*buff)[k-1])
				    &&
				    isletter((*buff)[k-2])
				    )
				  {
				    (*buff)[len] = 0;
				    lastword.setright(*buff, k+1);
				    buff->truncate(k+2);
				    (*buff)[k+1] = '-';
				    (*buff)[k+2] = '\0';
				    laststartline = lastsizes[k+1];
				    buff->resize();
				    for (int j = 0; j < lastword.length(); j++)
				      {
					lastsizes[j] = lastsizes[j+k+1];
				      }
				    return true;
				  }
			      }
			  }
			else
			*/
			  {
			    for (int k = lastk; k >= i && k >= 1; k--)
			      {
				if (
				    /*
				      (
				      k < len-3
				      &&
				      k >= 1
				      &&
				      isletter((*buff)[k+3])
				      &&
				      isletter((*buff)[k+2])
				      &&
				      isconsonant((*buff)[k+1])
				      &&
				      ((*buff)[k+1] != 'y')
				      &&
				      ((*buff)[k+1] != 'h')
				      &&
				      isconsonant((*buff)[k])
				      &&
				      ((*buff)[k] != 'h')
				      &&
				      isletter((*buff)[k-1])
				      )
				      ||
				    */
				    (
				     isletter((*buff)[k+3])
				     &&
				     isletter((*buff)[k+2])
				     &&
				     isconsonant((*buff)[k+1])
				     &&
				     ((*buff)[k+1] != 'y')
				     &&
				     isletter((*buff)[k])
				     &&
				     ((*buff)[k] != 'h')
				     &&
				     isletter((*buff)[k-1])
				     && // Do not hyphenate when the first part ends with a vowel,
				     // and the second starts with the two consonants.
				     // Examples: "co-nsona-nts" -> "con-sonants",
				     // "hy-phenation" -> "hyp-henation" etc.
				     !( isvowel( (*buff)[k] ) && isconsonant( (*buff)[k+2] ) )
				     )
				    )
				  {
				    (*buff)[len] = 0;
				    lastword.setright(*buff, k+1);
				    buff->truncate(k+2);
				    (*buff)[k+1] = '-';
				    (*buff)[k+2] = '\0';
				    laststartline = lastsizes[k+1];
				    //				    buff->resize();
				    for (int j = 0; j < lastword.length(); j++)
				      {
					lastsizes[j] = lastsizes[j+k+1];
				      }
				    return true;
				  }
			      }
			  }
			lastk = i;
		      }
		    if ((*buff)[i] == ' ')
		    {
			(*buff)[len] = 0;
			lastword.setright(*buff, i+1);
			buff->truncate(i);
			(*buff)[i] = '\0';
			laststartline = lastsizes[i+1];
			//			buff->resize();
			for (int j = 0; j < lastword.length(); j++)
			{
			    lastsizes[j] = lastsizes[j+i+1];
			}
			return true;
		    }
		}
		laststartline = lastsizes[len-1];
		(*buff)[len] = 0;
		lastword.setright(*buff, len - 1);
		buff->truncate(len-1);
		buff->addch('-', cs);
		for (int j = 0; j < lastword.length(); j++)
		{
		    lastsizes[j] = lastsizes[j+len];
		}
		break;
	    }
	}
    }
    (*buff)[len] = '\0';
    //    buff->resize();
    return moreleft;
}
Ejemplo n.º 7
0
static char * names_get_markov(struct link * chain)
{
  static char buf[1024];
  bool done;
  int consonant_count;
  int vowel_count;

  consonant_count = 0;
  vowel_count = 0;

  buf[0] = '\0';
  while(chain[(unsigned char) buf[0]].total == 0)  
    buf[0] = 'a' + get_rand('z' - 'a');
  
  if(isconsonant(buf[0]) == true)
    consonant_count++;
  else
    vowel_count++;
  
  done = false;
  for(unsigned int i = 1; done == false && i < sizeof buf; i++)
    {
      bool nextdone;
      int ctry;
      
      nextdone = false;
      ctry = 0;
      while(done == false && nextdone == false)
        {
          long n = get_rand(chain[(unsigned char) buf[i - 1]].total);
          unsigned int nchar = 0;
          for(nchar = 0; n >= (int) chain[(unsigned char) buf[i - 1]].next[nchar] && nchar < 0xff; nchar++)
            n -= chain[(unsigned char) buf[i - 1]].next[nchar];

          if(nchar == '\n')
            {
              buf[i] = '\0';
              done = true;
            }
          else
            {
              if(isconsonant(nchar) == false)
                {
                  buf[i] = nchar;
                  nextdone = true;
                  consonant_count = 0;
                  vowel_count++;
                }
              else
                {
                  if((int) get_rand(100) < getconsonantchance(vowel_count, consonant_count))
                    {
                      buf[i] = nchar;
                      nextdone = true;
                      consonant_count++;
                    }
                  ctry++;
                  if(ctry > 30)
                    {
                      buf[i] = '\0';
                      done = true;
                    }
                }
            }
        }
    }
  
  return buf;
}