コード例 #1
0
ファイル: ut_AString_Utility.cpp プロジェクト: achacha/AOS
void testSplit(int& iRet)
{
  LIST_AString names;
  AString str0("path0/path1/path2");
  str0.split(names, '/');
  ASSERT_UNIT_TEST(names.size() == 3, "AString::split", "0", iRet);
  
  LIST_AString::iterator it = names.begin();
  ASSERT_UNIT_TEST(!(*it).compare("path0"), "AString::split", "1", iRet);

  ++it;
  ASSERT_UNIT_TEST(!(*it).compare("path1"), "AString::split", "2", iRet);

  ++it;
  ASSERT_UNIT_TEST(!(*it).compare("path2"), "AString::split", "3", iRet);

  ++it;
  ASSERT_UNIT_TEST(it == names.end(), "AString::split", "3a", iRet);

  str0.assign("\\\\\\\\path0\\\\\\path1\\\\path2\\");
  names.clear();
  str0.split(names, '\\');
  ASSERT_UNIT_TEST(names.size() == 3, "AString::split", "4", iRet);

  it = names.begin();
  ASSERT_UNIT_TEST(!(*it).compare("path0"), "AString::split", "5", iRet);

  ++it;
  ASSERT_UNIT_TEST(!(*it).compare("path1"), "AString::split", "6", iRet);

  ++it;
  ASSERT_UNIT_TEST(!(*it).compare("path2"), "AString::split", "7", iRet);
  
  ++it;
  ASSERT_UNIT_TEST(it == names.end(), "AString::split", "8", iRet);

  str0.assign("_path0_path1_path2");
  names.clear();
  str0.split(names, '_');
  ASSERT_UNIT_TEST(names.size() == 3, "AString::split", "9", iRet);
  
  it = names.begin();
  ASSERT_UNIT_TEST(!(*it).compare("path0"), "AString::split", "10", iRet);

  ++it;
  ASSERT_UNIT_TEST(!(*it).compare("path1"), "AString::split", "11", iRet);

  ++it;
  ASSERT_UNIT_TEST(!(*it).compare("path2"), "AString::split", "12", iRet);

  ++it;
  ASSERT_UNIT_TEST(it == names.end(), "AString::split", "13", iRet);
}
コード例 #2
0
void AOSAdminCommand_list::_process(AOSAdminCommandContext& context)
{
  //a_Display list of objects
  LIST_AString objectNames;
  m_Services.useAdminRegistry().listAdminObjects(objectNames);

  LIST_AString::iterator it = objectNames.begin();
  while (it != objectNames.end())
  {
    AXmlElement& e = context.useModel().useRoot().addElement(ASW("object",6));
    e.addAttribute(ASW("name",4), *it);

    ++it;
  }
}
コード例 #3
0
ファイル: tSoundex.cpp プロジェクト: achacha/AOS
void doit(const AString& input)
{
  LIST_AString words;
  input.split(words);

  for (LIST_AString::iterator it = words.begin(); it != words.end(); ++it)
  {
    AString tmp;
    AString output;
    AWordUtility::getPhoneticForm(*it, tmp);
    AWordUtility::getSoundsLikeForm(tmp, output);

    std::cout << *it << " : " << tmp << " : " << output << std::endl;
  }
}
コード例 #4
0
void ATemplateNodeHandler_DADA::Node::_appendWordType(ADadaDataHolder *pddh, MAP_AString_AString& globals, const AString& strType, AOutputBuffer& target)
{
  //a_First remove control tags "TYPE:controltag1,controltag2,..."
  AString strTypeName, strControl;
  LIST_AString listControlNames;
  size_t pos = strType.find(':');
  if (AConstant::npos != pos)
  {
    strType.peek(strTypeName, 0, pos);
    strTypeName.makeLower();

    strType.peek(strControl, pos+1);
    strControl.makeLower();
    strControl.split(listControlNames, ',', AConstant::ASTRING_WHITESPACE);
  }
  else
  {
    strTypeName.assign(strType);
    strTypeName.makeLower();
  }

  ADadaDataHolder::WORDMAP::iterator it = pddh->useWordMap().find(strTypeName);
  if (pddh->useWordMap().end() != it)
  {
    VECTOR_AString& vec = (*it).second;
    u4 index = ARandomNumberGenerator::get().nextRange((int)vec.size());
    
    AString strSaveVariable;
    AString str(vec.at(index));
    
    //a_Apply control code actions
    LIST_AString::iterator itN = listControlNames.begin();
    while (itN != listControlNames.end())
    {
      if ('$' == (*itN).at(0, '\x0'))
      {
        //a_Add variable to global map
        (*itN).peek(strSaveVariable, 1);
        globals[strSaveVariable] = str;
        strSaveVariable.clear();
      }
      else if (!strTypeName.compare("verb"))
      {
        //a_Verb only control
        if (!(*itN).compare("present", 7))
        {
          if (AConstant::npos != AWordUtility::sstr_Vowels.find(str.last()))
          {
            //a_Vowel at the end is removed and replaced with "ing"
            str.rremove(1);
          }
          str.append("ing", 3);
        }
        else if (!(*itN).compare("past", 4))
        {
          if (AConstant::npos == AWordUtility::sstr_Vowels.find(str.last()))
          {
            str.append("ed", 2);
          }
          else
          {
            str.append("d", 1);
          }
        }
      }

      if (!(*itN).compare("article", 7))
      {
        AString strTemp(str);
        if (AConstant::npos == AWordUtility::sstr_Vowels.find(str.at(0)))
        {
          str.assign("a ", 2);
        }
        else
        {
          str.assign("an ", 3);
        }
        str.append(strTemp);
      }

      if (!(*itN).compare("plural", 6))
      {
        AString strTemp;
        AWordUtility::getPlural(str, strTemp);
        str.assign(strTemp);
      }

      if (!(*itN).compare("uppercase", 9))
      {
        str.makeUpper();
      }

      if (!(*itN).compare("lowercase", 9))
      {
        str.makeLower();
      }

      if (!(*itN).compare("proper", 6))
      {
        str.use(0) = (u1)toupper(str.at(0));

        size_t nextStart;
        size_t nextSpace = str.find(' ', 1);
        while (AConstant::npos != nextSpace)
        {
          nextStart = nextSpace + 1;
          if (nextStart < str.getSize())
            str.use(nextStart) = (u1)toupper(str.at(nextStart));
          else
            break;

          nextSpace = str.find(' ', nextStart);
        }
      }

      ++itN;
    }
    
    target.append(str);
  }
  else
  {
    //a_Unknown type, pass through as is.
    target.append('%');
    target.append(strType);
    target.append('%');
  }
}
コード例 #5
0
void ATemplateNodeHandler_DADA::Node::_appendVariable(ADadaDataHolder *pddh, MAP_AString_AString& globals, const AString& strType, AOutputBuffer& target)
{
  AASSERT(this, strType.getSize() > 0);

  AString strTypeName, strControl;
  LIST_AString listControlNames;
  size_t pos = strType.find(':');
  if (AConstant::npos != pos)
  {
    strType.peek(strTypeName, 0, pos);
    strTypeName.makeLower();

    strType.peek(strControl, pos+1);
    strControl.makeLower();
    strControl.split(listControlNames, ',', AConstant::ASTRING_WHITESPACE);
  }
  else
  {
    strTypeName.assign(strType);
    strTypeName.makeLower();
  }

  //a_Find it in the global lookup
  MAP_AString_AString::iterator it = globals.find(strTypeName);
  if (it != globals.end())
  {
    AString str((*it).second);

    LIST_AString::iterator itN = listControlNames.begin();
    while (itN != listControlNames.end())
    {
      if (!(*itN).compare("article", 7))
      {
        AString strTemp(str);
        if (AConstant::npos == AWordUtility::sstr_Vowels.find(str.at(0)))
        {
          str.assign("a ", 2);
        }
        else
        {
          str.assign("an ", 3);
        }
        str.append(strTemp);
      }

      if (!(*itN).compare("plural", 6))
      {
        AString strTemp;
        AWordUtility::getPlural(str, strTemp);
        str.assign(strTemp);
      }

      if (!(*itN).compare("uppercase", 9))
      {
        str.makeUpper();
      }

      if (!(*itN).compare("lowercase", 9))
      {
        str.makeLower();
      }

      if (!(*itN).compare("proper", 6))
      {
        str.use(0) = (u1)toupper(str.at(0));

        size_t nextStart;
        size_t nextSpace = str.find(' ', 1);
        while (AConstant::npos != nextSpace)
        {
          nextStart = nextSpace + 1;
          if (nextStart < str.getSize())
            str.use(nextStart) = (u1)toupper(str.at(nextStart));
          else
            break;

          nextSpace = str.find(' ', nextStart);
        }
      }

      ++itN;
    }

    target.append(str);
  }
  else
  {
    //a_Not found in global map
  }
}