Пример #1
0
  void MzTabParameterList::fromCellString(const String& s)
  {
    String lower = s;
    lower.toLower().trim();

    if (lower == "null")
    {
      setNull(true);
    }
    else
    {
      String ss = s;
      std::vector<String> fields;
      ss.split("|", fields);
      for (Size i = 0; i != fields.size(); ++i)
      {
        MzTabParameter p;
        lower = fields[i];
        lower.toLower().trim();
        if (lower == "null")
        {
          throw Exception::ConversionError(__FILE__, __LINE__, __PRETTY_FUNCTION__, String("MzTabParameter in MzTabParameterList must not be null '") + s);
        }
        p.fromCellString(fields[i]);
        parameters_.push_back(p);
      }
    }
  }
Пример #2
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
bool XmlElementImpl::getAttributeBool(const String& attributeName, bool defaultVal, bool* found /*= NULL*/) const
{
    if (found) *found = false;

    String val;
    const char* attrValue = Attribute(attributeName.toUtf8().ptr());
    if (attrValue)
    {
        val = attrValue;
    }
    
    if (val.isEmpty()) return defaultVal;

    if (found) *found = true;

    if (val[0] == '1') return true;
    if (val[0] == '0') return false;

    val.toLower();

    if (val == "yes" || val == "on" || val == "true") return true;
    if (val == "no"  || val == "off" || val == "false") return false;

    return defaultVal;
}
Пример #3
0
   IContent* ContentManager::load(const String& name)
   {
      IContent* presult = NULL;

      String path = name + UTEXT(".c2d");
      path.toLower();

      File* pfile = FileSystem::getInstance().open(path, File::ERead | File::EBinary);
      if ( pfile != NULL )
      {
         Uuid uuid;
         FileReaderStream stream(*pfile);
         uuid.read(stream);

         ContentModule* pmodule = findModule(uuid);
         if ( pmodule != NULL )
         {
            ContentReader& reader = pmodule->getReader();
            reader.setContentManager(*this);
            reader.setGraphicsDevice(mpDevice);
            reader.setPhysicsSimulator(mpSimulator);
            reader.setSoundManager(mpSoundManager);

            presult = reader.read(stream);
            if ( presult != NULL )
            {
               presult->setFilename(name);
            }
         }
      }

      return presult;
   }
Пример #4
0
void CompileContext::addClass(ASTClass* pclass)
{
   String lowercasename = pclass->getFullName();
   lowercasename.toLower();
   
   mClasses[lowercasename] = pclass;
}
Пример #5
0
bool CompileContext::hasClass(const String& classname) const
{
   String lowercasename = classname;
   lowercasename.toLower();

   return mClasses.find(lowercasename) != mClasses.end();
}
Пример #6
0
void testArrayType(const Array<T>& x)
{
    WsmToCimRequestMapper mapper((CIMRepository*) 0);

    // Create a NULL CIMValue of the appropriate type. Normally type
    // info is retrieved from the repository.
    CIMValue tmp(x);
    CIMValue cimValue(tmp.getType(), tmp.isArray());

    // Create WsmValue out of the given array
    Array<String> arr;
    for (Uint32 i = 0; i < x.size(); i++)
    {
        String str = CIMValue(x[i]).toString();
        if (tmp.getType() == CIMTYPE_BOOLEAN)
        {
            str.toLower();
        }
        arr.append(str);
    }

    WsmValue wsmValue(arr);
    mapper.convertWsmToCimValue(wsmValue, CIMNamespaceName(), cimValue);
    PEGASUS_TEST_ASSERT(tmp == cimValue);
}
Пример #7
0
  TOPPASEdge::EdgeStatus TOPPASEdge::getListToolStatus_(TOPPASInputFileListVertex * source_input_list, TOPPASToolVertex * target_tool, int target_param_index)
  {
    QVector<TOPPASToolVertex::IOInfo> target_input_files;
    target_tool->getInputParameters(target_input_files);
    if (target_param_index >= target_input_files.size())
    {
      return ES_TOOL_API_CHANGED;
    }

    const QStringList & file_names = source_input_list->getFileNames();
    if (file_names.empty())
    {
      // file names are not specified yet
      return ES_NOT_READY_YET;
    }

    if (target_param_index < 0)
    {
      return ES_NO_TARGET_PARAM;
    }

    const TOPPASToolVertex::IOInfo & target_param = target_input_files[target_param_index];
    StringList target_param_types = target_param.valid_types;

    if (target_param_types.empty())
    {
      // no file types specified --> allow
      return ES_VALID;
    }

    // check file type compatibility
    foreach(const QString &q_file_name, file_names)
    {
      bool type_mismatch = true;
      const String & file_name = String(q_file_name);
      String::SizeType extension_start_index = file_name.rfind(".");
      if (extension_start_index != String::npos)
      {
        String extension = file_name.substr(extension_start_index + 1);
        extension.toLower();
        for (StringList::iterator it = target_param_types.begin(); it != target_param_types.end(); ++it)
        {
          String other_ext = *it;
          other_ext.toLower();
          if (extension == other_ext || extension == "gz" || extension == "bz2")
          {
            type_mismatch = false;
            break;
          }
        }
      }

      if (type_mismatch)
      {
        return ES_FILE_EXT_MISMATCH;
      }
    }
Пример #8
0
  void MzTabParameter::fromCellString(const String& s)
  {
    String lower = s;
    lower.toLower().trim();
    if (lower == "null")
    {
      setNull(true);
    }
    else
    {
      StringList fields;
      String field;
      bool in_quotes = false;
      for (String::const_iterator sit = s.begin(); sit != s.end(); ++sit)
      {
        if (*sit == '\"') // start or end of quotes
        {
          in_quotes = !in_quotes;
        }
        else if (*sit == ',') // , encountered
        {
          if (in_quotes) // case 1: , in quote
          {
            field += ','; // add , (no split)
          }
          else // split at , if not in quotes
          {
            fields.push_back(field.trim());
            field.clear();
          }
        }
        else if (*sit != '[' && *sit != ']')
        {
          // skip leading ws
          if (*sit == ' ' && field.empty())
          {
            continue;
          }
          field += *sit;
        }
      }

      fields.push_back(field.trim());

      if (fields.size() != 4)
      {
        throw Exception::ConversionError(__FILE__, __LINE__, __PRETTY_FUNCTION__, String("Could not convert String '") + s + "' to MzTabParameter");
      }

      CV_label_ = fields[0];
      accession_ = fields[1];
      name_ = fields[2];
      value_ = fields[3];
    }
  }
Пример #9
0
	void LibConfigProgram::expandModuleNames()
	{
		String item;

		// Lowercase
		const String::List::iterator end = pOptModules.end();
		for (String::List::iterator i = pOptModules.begin(); i != end; ++i)
		{
			item = *i;
			*i = item.toLower();
		}

		bool mustContinue;
		do
		{
			mustContinue = false;
			const String::List::iterator end = pOptModules.end();
			for (String::List::iterator i = pOptModules.begin(); i != end; ++i)
			{
				if (i->empty())
				{
					// We have no interest in empty strings
					pOptModules.erase(i);
					mustContinue = true;
					break;
				}
				if (String::npos != i->find_first_of(YUNI_LIBYUNI_CONFIG_SEPARATORS))
				{
					// This item seems to be actually a list of several requested modules
					// We will split the string to get the real list
					item = *i;
					pOptModules.erase(i);
					item.split(pOptModules, YUNI_LIBYUNI_CONFIG_SEPARATORS, false, false, true);
					mustContinue = true;
					break;
				}
				if (i->first() == '+')
				{
					// The symbol `+` enables a module, but this is already a default behavior
					item.assign(*i, 1, i->size() - 1);
					*i = item;
					continue;
				}
				if (i->first() == '-')
				{
					// The symbol `-` disables a module, so we have to remove all existing entries
					mustContinue = true;
					item.assign(*i, 1, i->size() - 1);
					pOptModules.erase(i);
					pOptModules.remove(item);
					break;
				}
			}
		} while (mustContinue);
	}
Пример #10
0
  void MzTabModification::fromCellString(const String& s)
  {
    String lower = s;
    lower.toLower().trim();
    if (lower == "null")
    {
      setNull(true);
    }
    else
    {
      if (!lower.hasSubstring("-")) // no positions? simply use s as mod identifier
      {
        mod_identifier_.set(String(s).trim());
      }
      else
      {
        String ss = s;
        ss.trim();
        std::vector<String> fields;
        ss.split("-", fields);

        if (fields.size() != 2)
        {
          throw Exception::ConversionError(__FILE__, __LINE__, __PRETTY_FUNCTION__, String("Can't convert to MzTabModification from '") + s);
        }
        mod_identifier_.fromCellString(fields[1].trim());

        std::vector<String> position_fields;
        fields[0].split("|", position_fields);

        for (Size i = 0; i != position_fields.size(); ++i)
        {
          Size spos = position_fields[i].find_first_of("[");

          if (spos == std::string::npos) // only position information and no parameter
          {
            pos_param_pairs_.push_back(std::make_pair(position_fields[i].toInt(), MzTabParameter()));
          }
          else
          {
            // extract position part
            Int pos = String(position_fields[i].begin(), position_fields[i].begin() + spos).toInt();

            // extract [,,,] part
            MzTabParameter param;
            param.fromCellString(position_fields[i].substr(spos));
            pos_param_pairs_.push_back(std::make_pair(pos, param));
          }
        }
      }
    }
  }
Пример #11
0
 void MzTabString::set(const String& value)
 {
   String lower = value;
   lower.toLower().trim();
   if (lower == "null")
   {
     setNull(true);
   }
   else
   {
     value_ = value;
     value_.trim();
   }
 }
Пример #12
0
void testSimpleType(const T& x)
{
    WsmToCimRequestMapper mapper((CIMRepository*) 0);

    // Create a NULL CIMValue of the appropriate type. Normally type
    // info is retrieved from the repository.
    CIMValue tmp(x);
    CIMValue cimValue(tmp.getType(), tmp.isArray());
    String str = tmp.toString();
    if (tmp.getType() == CIMTYPE_BOOLEAN)
    {
        str.toLower();
    }
    WsmValue wsmValue(str);
    mapper.convertWsmToCimValue(wsmValue, CIMNamespaceName(), cimValue);
    PEGASUS_TEST_ASSERT(tmp == cimValue);
}
Пример #13
0
// proxy auth header username extraction
int digestinstance::identify(Socket &peercon, Socket &proxycon, HTTPHeader &h, std::string &string)
{
    // don't match for non-digest auth types
    String t = h.getAuthType();
    t.toLower();
    if (t != "digest")
        return DGAUTH_NOMATCH;
    // extract username
    string = h.getRawAuthData();
    if (string.length() > 0) {
        String temp(string);
        temp = temp.after("username=\"");
        temp = temp.before("\"");
        string = temp;
        return DGAUTH_OK;
    }
    return DGAUTH_NOMATCH;
}
Пример #14
0
 void EnzymesDB::addEnzyme_(const Enzyme* r)
 {
   // add to internal storage
   const_enzymes_.insert(r);
   // add to internal indices (by name and its synonyms)
   String name = r->getName();
   enzyme_names_[name] = r;
   enzyme_names_[name.toLower()] = r;
   for (set<String>::const_iterator it = r->getSynonyms().begin(); it != r->getSynonyms().end(); ++it)
   {
     enzyme_names_[*it] = r;
   }
   // ... and by regex
   if (r->getRegEx() != "")
   {
     enzyme_regex_[r->getRegEx()] = r;
   }    
   return;
 }
Пример #15
0
String getFileType(String input,char delim){
	String f="";

	int end=input.size();
	int start=input.size();

	for(int i=input.size()-1; i>0; i--){
		if(input[i]==delim){
			break;
		}else{
			start--;
		}
	}

	input=input.substr(start,end);
	input=input.toLower();

	return input;
}
Пример #16
0
 void MzTabDouble::fromCellString(const String& s)
 {
   String lower = s;
   lower.toLower().trim();
   if (lower == "null")
   {
     setNull(true);
   }
   else if (lower == "nan")
   {
     setNaN();
   }
   else if (lower == "inf")
   {
     setInf();
   }
   else // default case
   {
     set(lower.toDouble());
   }
 }
Пример #17
0
 void MzTabDoubleList::fromCellString(const String& s)
 {
   String lower = s;
   lower.toLower().trim();
   if (lower == "null")
   {
     setNull(true);
   }
   else
   {
     String ss = s;
     std::vector<String> fields;
     ss.split("|", fields);
     for (Size i = 0; i != fields.size(); ++i)
     {
       MzTabDouble ds;
       ds.fromCellString(fields[i]);
       entries_.push_back(ds);
     }
   }
 }
Пример #18
0
  void MzTabSpectraRef::fromCellString(const String& s)
  {
    String lower = s;
    lower.toLower().trim();
    if (lower == "null")
    {
      setNull(true);
    }
    else
    {
      String ss = s;
      std::vector<String> fields;
      ss.split(":", fields);
      if (fields.size() != 2)
      {
        throw Exception::ConversionError(__FILE__, __LINE__, __PRETTY_FUNCTION__, String("Can not convert to MzTabSpectraRef from '") + s);
      }

      spec_ref_ = fields[1];
      ms_run_ = (Size)(fields[0].substitute("ms_run[", "").remove(']').toInt());
    }
  }
Пример #19
0
// return a modified accept-encoding header, based on the one supplied,
// but with "identity" added and only supported encodings allowed.
String HTTPHeader::modifyEncodings(String e)
{

	// There are 4 types of encoding: gzip, deflate, compress and identity
	// deflate is in zlib format
	// compress is in unix compress format
	// identity is uncompressed and supported by all browsers (obviously)
	// we do not support compress

	e.toLower();
	String o("Accept-Encoding: identity");
#if ZLIB_VERNUM < 0x1210
#warning 'Accept-Encoding: gzip' is disabled
#else
	if (e.contains("gzip")) {
		o += ",gzip";
	}
#endif
	if (e.contains("deflate")) {
		o += ",deflate";
	}

	return o;
}
Пример #20
0
bool CompileContext::loadClass(const String& classname)
{
   String lowercasename = classname;
   lowercasename.toLower();

   ClassMap::iterator it = mClasses.find(lowercasename);
   if ( it == mClasses.end() )
   {
      try
      {
         ASTRoot& root = mCompiler.load(classname);
         std::vector<ASTClass*> classes;
         root.collectClasses(classes);
         auto append = [this](ASTClass* pclass) { addClass(pclass); };
         std::for_each(classes.begin(), classes.end(), append);
      }
      catch ( FileNotFoundException* )
      {
         return false;
      }
   }

   return true;
}
Пример #21
0
 void MzTabBoolean::fromCellString(const String& s)
 {
   String lower = s;
   lower.toLower().trim();
   if (lower == "null")
   {
     setNull(true);
   }
   else
   {
     if (s == "0")
     {
       set(false);
     }
     else if (s == "1")
     {
       set(true);
     }
     else
     {
       throw Exception::ConversionError(__FILE__, __LINE__, __PRETTY_FUNCTION__, String("Could not convert String '") + s + "' to MzTabBoolean");
     }
   }
 }
Пример #22
0
	void Http::proc(void* /*param*/)
	{
		bStop = false;

		if (!Paths::Exists(Paths::ExtractFilePath(filename)))
			Paths::MakeDir(Paths::ExtractFilePath(filename));

		SocketTCP   sock;
		char		buffer[4096];
		String      realFilename = filename;
		String      tmpFile = String(filename) << ".part";
		Stream		f(tmpFile, Yuni::Core::IO::OpenMode::write);
		int         count;
		int         crfound = 0;
		int         lffound = 0;

		if (!f.opened())
		{
			LOG_ERROR(LOG_PREFIX_NET << "httpGetFile: Could not open file " << tmpFile << " for writing !");
			return;        // Error can't open file
		}

		/* open the socket and connect to the server */
		sock.open(servername, 80);
		if(!sock.isOpen())
		{
			LOG_ERROR(LOG_PREFIX_NET << "httpGetFile: Could not open socket !");
			f.close();
			remove(tmpFile.c_str());
			return;
		}

		sock.setNonBlockingMode(true);      // We want it to be able to detect end of file ;)

		String tmpBuf;
		tmpBuf << "GET " << _request << " HTTP/1.0\r\nHost:" << servername << "\nAccept: */*\r\nUser-Agent: TA3D\r\nConnection: close\r\n\r\n";

		uint32 timer(msec_timer);
		sock.send(tmpBuf.data(), tmpBuf.size());
		if (!sock.isOpen())
		{
			LOG_ERROR(LOG_PREFIX_NET << "httpGetFile: Could not send request to server !");
			f.close();
			remove(tmpFile.c_str());
			return;
		}

		pos = 0;
		size = 0;
		String header;

		while (!bStop)
		{
			timer = msec_timer;
			do
			{
				count = sock.recv(buffer, sizeof(buffer) - 1);
				if (count == 0)
				{
					if (suspend(1))
					{
						sock.close();
						f.close();
						remove(tmpFile.c_str());
						return;
					}
				}
			}
			while(count == 0 && msec_timer - timer < 60000 && !bStop);
			if (msec_timer - timer >= 60000 || bStop)
				sock.close();
			if(count < 0)
			{
				sock.close();
				f.close();
				if (pos == size)
				{
					Paths::Files::Copy(tmpFile, realFilename, true);
					LOG_DEBUG(LOG_PREFIX_NET << "File successfully downloaded : " << realFilename);
				}
				else
				{	LOG_DEBUG(LOG_PREFIX_NET << "Download failed : " << realFilename);	}
				remove(tmpFile.c_str());
				return;
			}
			if(count > 0)
			{
				/* parse out the HTTP header */
				if(lffound < 2)
				{
					int i;

					for (i = 0; i < count; ++i)
					{
						header << buffer[i];
						if(buffer[i] == 0x0D)
							++crfound;
						else
						{
							if (buffer[i] == 0x0A)
								++lffound;
							else
								/* reset the CR and LF counters back to 0 */
								crfound = lffound = 0;
						}
						if (lffound == 2)
						{
							/* i points to the second LF */
							/* output the buffer to the file */
							f.write( (char*)(buffer+i+1), count-i-1 );
							pos += count-i-1;
							size = Math::Max(size, pos);
							break;
						}
					}
					if (lffound >= 2)
					{
						header.toLower();
						String::Size offset = header.find("content-length: ");
						if (offset != String::npos)
						{
							header.erase(0, offset + 16);
							header.trimRight(" \n\t");
							size = header.to<int>();
							LOG_DEBUG("header = " << header);
							LOG_DEBUG("Http: size = " << size);
						}
					}
				}
				else
				{
					f.write( (const char*)buffer, count );
					pos += count;
					size = Math::Max(size, pos);
				}
			}
		}
		sock.close();
		f.close();
		remove(tmpFile.c_str());
		LOG_ERROR(LOG_PREFIX_NET << "Http: Download interrupted!");
	}
Пример #23
0
std::string Windows::normalizePath (const std::string& path)
{
	String tmp = path;
	return tmp.toLower().replaceAll("\\", "/");
}
Пример #24
0
int test(char** argv)
{
    verbose = getenv("PEGASUS_TEST_VERBOSE") ? true : false;

    String s1 = "Hello World";
    String s2 = s1;
    String s3(s2);

    PEGASUS_TEST_ASSERT(String::equal(s1, s3));

    // Test append characters to String
    String s4 = "Hello";
    s4.append(Char16(0x0000));
    s4.append(Char16(0x1234));
    s4.append(Char16(0x5678));
    s4.append(Char16(0x9cde));
    s4.append(Char16(0xffff));

    {
#ifdef HAVE_SSTREAM
        stringstream os;
#endif
#ifdef HAVE_STRSTREAM
        ostrstream os;
#endif
        os << s4;
#ifdef HAVE_STRSTREAM
        os.put('\0');
#endif
#ifndef PEGASUS_HAS_ICU
        const char EXPECTED[] = "Hello\\x0000\\x1234\\x5678\\x9CDE\\xFFFF";
#else
        CString cstr = s4.getCString();
        const char * EXPECTED = (const char *)cstr;
#endif

#ifdef HAVE_SSTREAM
    string os_str = os.str();
    const char* tmp = os_str.c_str();
#endif
#ifdef HAVE_STRSTREAM
        char *tmp = os.str();
#endif

        PEGASUS_TEST_ASSERT(strcmp(EXPECTED, tmp) == 0);
#ifdef PEGASUS_PLATFORM_AIX_RS_IBMCXX
        os.freeze(false);
#else

#ifdef HAVE_STRSTREAM
        delete tmp;
#endif

#endif
    }

    {
        // Test getCString
        const char STR0[] = "one two three four";
        String s = STR0;
        PEGASUS_TEST_ASSERT(strcmp(s.getCString(), STR0) == 0);
    }

    {
        // Test remove
        String s = "abcdefg";
        s.remove(3, 3);
        PEGASUS_TEST_ASSERT(String::equal(s, "abcg"));
        PEGASUS_TEST_ASSERT(s.size() == 4);

        s = "abcdefg";
        s.remove(3, 4);
        PEGASUS_TEST_ASSERT(String::equal(s, "abc"));
        PEGASUS_TEST_ASSERT(s.size() == 3);

        s = "abcdefg";
        s.remove(3);
        PEGASUS_TEST_ASSERT(String::equal(s, "abc"));
        PEGASUS_TEST_ASSERT(s.size() == 3);

        s = "abc";
        s.remove(3);
        PEGASUS_TEST_ASSERT(String::equal(s, "abc"));
        PEGASUS_TEST_ASSERT(s.size() == 3);

        s = "abc";
        s.remove(0);
        PEGASUS_TEST_ASSERT(String::equal(s, ""));
        PEGASUS_TEST_ASSERT(s.size() == 0);

        s = "abc";
        s.remove(0, 1);
        PEGASUS_TEST_ASSERT(String::equal(s, "bc"));
        PEGASUS_TEST_ASSERT(s.size() == 2);

        String t1 = "HELLO";
        String t2 = t1;
        t2.toLower();
        PEGASUS_TEST_ASSERT(String::equal(t1, "HELLO"));
        PEGASUS_TEST_ASSERT(String::equal(t2, "hello"));
    }

    {
        // another test of the append method
        String t1 = "one";
        t1.append(" two");
        PEGASUS_TEST_ASSERT(String::equal(t1, "one two"));
        t1.append(' ');
        t1.append('t');
        t1.append('h');
        t1.append('r');
        t1.append("ee");
        PEGASUS_TEST_ASSERT(String::equal(t1,"one two three"));

        // used as example in Doc.
        String test = "abc";
        test.append("def");
        PEGASUS_TEST_ASSERT(test == "abcdef");
    }

    // Test of the different overload operators
    {
        // Test the == overload operator
        String t1 = "one";
        String t2 = "one";
        PEGASUS_TEST_ASSERT(t1 == "one");
        PEGASUS_TEST_ASSERT("one" == t1);
        PEGASUS_TEST_ASSERT(t1 == t2);
        PEGASUS_TEST_ASSERT(t2 == t1);
        PEGASUS_TEST_ASSERT(String("one") == "one");

        const char STR0[] = "one two three four";
        String s = STR0;
        CString tmp = s.getCString();
        PEGASUS_TEST_ASSERT(tmp == s);
        PEGASUS_TEST_ASSERT(s == tmp);
    }

    {
        // Tests of the + Overload operator
        String t1 = "abc";
        String t2 = t1 + t1;
        PEGASUS_TEST_ASSERT(t2 == "abcabc");
        t1 = "abc";
        t2 = t1 + "def";
        PEGASUS_TEST_ASSERT(t2 == "abcdef");

        t1 = "ghi";
        PEGASUS_TEST_ASSERT(t1 == "ghi");

        // ATTN: the following fails because there
        // is no single character overload operator
        // KS: Apr 2001
        // t2 = t1 + 'k' + 'l' + 'm' + "nop";
        t2 = t1 + "k" + "l" + "m" + "nop";
        PEGASUS_TEST_ASSERT(t2 == "ghiklmnop");
        PEGASUS_TEST_ASSERT(String::equal(t2,"ghiklmnop"));

        // add tests for != operator.

        t1 = "abc";
        PEGASUS_TEST_ASSERT(t1 != "ghi");
        PEGASUS_TEST_ASSERT(t1 != t2);

        // add tests for other compare operators

        // Operater <
        t1 = "ab";
        t2 = "cde";
        PEGASUS_TEST_ASSERT(t1 < t2);
        PEGASUS_TEST_ASSERT(t1 <= t2);
        PEGASUS_TEST_ASSERT(t2 > t1);
        PEGASUS_TEST_ASSERT(t2 >=t1);
        PEGASUS_TEST_ASSERT(String::compare(t1,t2) < 0);
        PEGASUS_TEST_ASSERT(String::compare(t2,t1) > 0);
        PEGASUS_TEST_ASSERT(String::compare(t1, t2, 1) < 0);
        PEGASUS_TEST_ASSERT(String::compare(t2, t1, 1) > 0);
        PEGASUS_TEST_ASSERT(String::compare(t1, t2, 10) < 0);
        PEGASUS_TEST_ASSERT(String::compare(t2, t1, 10) > 0);
        PEGASUS_TEST_ASSERT(String::compare(t1, t2, 0) == 0);
        t2 = t1;
        PEGASUS_TEST_ASSERT(t1 <= t2);
        PEGASUS_TEST_ASSERT(t1 >= t2);
        PEGASUS_TEST_ASSERT(String::compare(t1, t2) == 0);
        PEGASUS_TEST_ASSERT(String::compare(t1, t2, 0) == 0);
        PEGASUS_TEST_ASSERT(String::compare(t1, t2, 1) == 0);
        PEGASUS_TEST_ASSERT(String::compare(t1, t2, 10) == 0);


        // Tests for compare with same length
        t1 = "abc";
        t2 = "def";
        PEGASUS_TEST_ASSERT(t1 < t2);
        PEGASUS_TEST_ASSERT(String::compare(t1, t2) < 0);
        PEGASUS_TEST_ASSERT(String::compare(t2, t1) > 0);
        PEGASUS_TEST_ASSERT(String::compare(t1, t2, 10) < 0);
        PEGASUS_TEST_ASSERT(String::compare(t1, t2, 0) == 0);

        t1 = "abc";
        t2 = "ABC";
        PEGASUS_TEST_ASSERT(String::equalNoCase(t1,t2));
        PEGASUS_TEST_ASSERT(!String::equal(t1,t2));
        PEGASUS_TEST_ASSERT(String::compareNoCase(t1,t2) == 0);
        t1.toUpper();
        t2.toLower();
        PEGASUS_TEST_ASSERT(String::equal(t1, "ABC"));
        PEGASUS_TEST_ASSERT(String::equal(t2, "abc"));

        t1 = "1000";
        t2 = "1001";
        PEGASUS_TEST_ASSERT(String::compareNoCase(t1,t2) < 0);
        PEGASUS_TEST_ASSERT(String::compare(t1, t2) < 0);
        PEGASUS_TEST_ASSERT(String::compare(t1, t2, 3) == 0);
        PEGASUS_TEST_ASSERT(String::compare(t1, t2, 4) < 0);

#ifdef PEGASUS_HAS_ICU
        //
        // Strings used to test non-ascii case mappings
        // Tests context sensitve mappings (eg. greek)
        // Tests expansion after mapping (eg german)
        //

        // Lower case german and greek
        // --latin small letter sharp s (german) (2 of these to cause
        //  ICU overflow error inside of String)
        // --greek small letter sigma (followed by another letter)
        // --latin small a
        // --greek small letter sigma (NOT followed by another letter)
        const Char16 lowermap[] = {
                                   0xdf,
                                   0xdf,
                                   0x3c3,
                                   'a',
                                   0x3c2,
                                   0x00};
        String degkLow(lowermap);

        // Needed because the german char does not round trip
        // after an uppercase followed by lower case.
        // --latin small letters 's' 's' (4 of these due to expansion)
        // --greek small letter sigma (followed by another letter)
        // --latin small a
        // --greek small letter sigma (NOT followed by another letter)
        const Char16 lowermap2[] = {
                                   's', 's', 's', 's',
                                   0x3c3,
                                   'a',
                                   0x3c2,
                                   0x00};
        String degkLow2(lowermap2);

        // Upper case greek and german
        // latin cap letter sharp s (german) (4 of these due to expansion)
        // greek cap letter sigma (followed by another letter)
        // latin cap A
        // greek cap letter sigma (NOT followed by another letter)
        const Char16 uppermap[] = {
                                  'S', 'S', 'S', 'S',
                                   0x3a3,
                                   'A',
                                   0x3a3,
                                   0x00};
        String degkUp(uppermap);


        PEGASUS_TEST_ASSERT(String::compareNoCase(degkLow,degkUp) == 0);
        // does a binary compare, so lower > upper
        PEGASUS_TEST_ASSERT(String::compare(degkLow,degkUp) > 0);
        PEGASUS_TEST_ASSERT(String::equalNoCase(degkLow,degkUp));

        String mapTest(degkLow);
        mapTest.toUpper();
        PEGASUS_TEST_ASSERT(String::equal(mapTest, degkUp));

        // Note that the German char does not round trip
        mapTest.toLower();
        PEGASUS_TEST_ASSERT(String::equal(mapTest, degkLow2));
#endif
    }

    {
        // Test of the [] operator
        String t1 = "abc";
        Char16 c = t1[1];
        // note c is Char16
        PEGASUS_TEST_ASSERT(c == 'b');

        //ATTN: test for outofbounds exception
        try
        {
            c = t1[200];
        }
        catch (IndexOutOfBoundsException&)
        {
        PEGASUS_TEST_ASSERT(true);
        }
    }

    {
        // Test the find function
        String t1 = "abcdef";
        String t2 = "cde";
        String t3 = "xyz";
        String t4 = "abc";
        String t5 = "abd";
        String t6 = "defg";
        PEGASUS_TEST_ASSERT(t1.find('c') == 2);
        PEGASUS_TEST_ASSERT(t1.find(t2)==2);
        PEGASUS_TEST_ASSERT(t1.find(t3)==PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(t1.find(t4)==0);
        PEGASUS_TEST_ASSERT(t1.find(t5)==PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(t1.find(t6)==PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(t1.find("cde")==2);
        PEGASUS_TEST_ASSERT(t1.find("def")==3);
        PEGASUS_TEST_ASSERT(t1.find("xyz")==PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(t1.find("a") ==0);

        // test for the case where string
        // partly occurs and then later
        // completely occurs
        String s = "this is an apple";
        PEGASUS_TEST_ASSERT(s.find("apple")==11);
        PEGASUS_TEST_ASSERT(s.find("appld")==PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(s.find("this")==0);
        PEGASUS_TEST_ASSERT(s.find("t")==0);
        PEGASUS_TEST_ASSERT(s.find("e")==15);
        s = "a";
        PEGASUS_TEST_ASSERT(s.find("b")==PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(s.find("a")==0);
        PEGASUS_TEST_ASSERT(s.find(s)==0);
        s = "aaaapple";
        PEGASUS_TEST_ASSERT(s.find("apple")==3);

        // 20020715-RK This method was removed from the String class
        //{
        //    String nameSpace = "a#b#c";
        //    nameSpace.translate('#', '/');
        //    PEGASUS_TEST_ASSERT(nameSpace == "a/b/c");
        //}
    }

    {
        //
        // Test String unicode enablement
        //

        char utf8chr[]    = {
                              '\xCE', '\x99', '\xCE', '\xBF', '\xCF', '\x8D',
                              '\xCE', '\xBD', '\xCE', '\xB9', '\xCE', '\xBA',
                              '\xCE', '\xBF', '\xCE', '\xBD', '\xCF', '\x84',
                              '\0'
                            }; // utf8 string with mutliple byte characters

        Char16 utf16chr[] = {
                              0x0399,0x03BF,0x03CD,0x03BD,0x03B9,
                              0x03BA,0x03BF,0x03BD,0x03C4,0x00
                            };  // utf16 representation of the utf8 string

        String utf16string(utf16chr);
        String utf8string(utf8chr);
        String utf16merge(utf8string.getChar16Data());

        CString temp = utf8string.getCString();
        CString temp2 = utf16string.getCString();

        PEGASUS_TEST_ASSERT(utf16string == utf8string);
        PEGASUS_TEST_ASSERT(utf16string == utf16merge);
        PEGASUS_TEST_ASSERT(utf16string == utf16chr);
        PEGASUS_TEST_ASSERT(utf8string  == utf16chr);

        PEGASUS_TEST_ASSERT(memcmp(utf8string.getChar16Data(),
                            utf16string.getChar16Data(),sizeof(utf16chr)) == 0);
        PEGASUS_TEST_ASSERT(strcmp(utf8string.getCString(),utf8chr) == 0);
        PEGASUS_TEST_ASSERT(strcmp(utf16string.getCString(),utf8chr) == 0);
        PEGASUS_TEST_ASSERT(strcmp(temp,utf8chr) == 0);
        PEGASUS_TEST_ASSERT(strcmp(temp2,utf8chr) == 0);

        Uint32 count = 0;
        Uint32 size = sizeof(utf8chr);
        while(count<size)
        {
                PEGASUS_TEST_ASSERT(isUTF8(&utf8chr[count]) == true);
                UTF8_NEXT(utf8chr,count);
        }

        // utf8 string with mutliple byte characters
        char utf8bad[] =
        {
            '\xFF','\xFF', '\xFF', '\0', '\0', '\0'
        };

        count = 0;
        size = 3;
        while(count<size)
        {
            PEGASUS_TEST_ASSERT(isUTF8(&utf8bad[count]) == false);
            UTF8_NEXT(utf8bad,count);
        }

        Char16 utf16Chars[] =
        {
        0x6A19, 0x6E96, 0x842C, 0x570B, 0x78BC,
        0x042E, 0x043D, 0x0438, 0x043A, 0x043E, 0x0434,
        0x110B, 0x1172, 0x1102, 0x1165, 0x110F, 0x1169, 0x11AE,
        0x10E3, 0x10DC, 0x10D8, 0x10D9, 0x10DD, 0x10D3, 0x10D8,
        0xdbc0, 0xdc01,
        0x05D9, 0x05D5, 0x05E0, 0x05D9, 0x05E7, 0x05D0, 0x05B8, 0x05D3,
        0x064A, 0x0648, 0x0646, 0x0650, 0x0643, 0x0648, 0x062F,
        0x092F, 0x0942, 0x0928, 0x093F, 0x0915, 0x094B, 0x0921,
        0x016A, 0x006E, 0x012D, 0x0063, 0x014D, 0x0064, 0x0065, 0x033D,
        0x00E0, 0x248B, 0x0061, 0x2173, 0x0062, 0x1EA6, 0xFF21, 0x00AA,
            0x0325, 0x2173, 0x249C, 0x0063,
        0x02C8, 0x006A, 0x0075, 0x006E, 0x026A, 0x02CC, 0x006B, 0x006F,
            0x02D0, 0x0064,
        0x30E6, 0x30CB, 0x30B3, 0x30FC, 0x30C9,
        0xFF95, 0xFF86, 0xFF7A, 0xFF70, 0xFF84, 0xFF9E,
        0xC720, 0xB2C8, 0xCF5B, 0x7D71, 0x4E00, 0x78BC,
        0xdbc0, 0xdc01,
        0x00};

        String ugly(utf16Chars);
        PEGASUS_TEST_ASSERT(ugly == utf16Chars);

        //
        // Test passing bad utf-8 into String
        //

        // A utf-8 sequence with a byte zeroed out in a bad spot
        char utf8bad1[]    = {
                              '\xCE', '\x99', '\xCE', '\xBF', '\xCF', '\x8D',
                              '\xCE', '\xBD', '\xCE', '\0', '\xCE', '\xBA',
                              '\xCE', '\xBF', '\xCE', '\xBD', '\xCF', '\x84',
                              '\0'
                            }; // utf8 string with mutliple byte characters

        // Test String(char *)
        try
        {
          // the first terminator causes invalid utf-8
          String tmp(utf8bad1);
          PEGASUS_TEST_ASSERT(false);
        }
        catch (Exception &)
        {
          // expect an error
        }

        // Test String(char *, Uint32)
        try
        {
          // bogus utf-8 char in the middle
          String tmp(utf8bad1, sizeof(utf8bad1)-1);
          PEGASUS_TEST_ASSERT(false);
        }
        catch (Exception &)
        {
          // expect an error
        }

        // Test String(char *, Uint32)
        try
        {
          // good, but the last utf-8 char extends past the last byte
          String tmp(utf8chr, sizeof(utf8chr) - 2);
          PEGASUS_TEST_ASSERT(false);
        }
        catch (Exception &)
        {
          // expect an error
        }

        // Test String::assign(char *)
        String assigntest(utf8chr);  // good so far
        try
        {
          // the first terminator causes invalid utf-8
          assigntest.assign(utf8bad1);  // bad
          PEGASUS_TEST_ASSERT(false);
        }
        catch (Exception &)
        {
          // expect an error
        }

        // Test String::assign(char *, Uint32)
        try
        {
          // bogus utf-8 char in the middle
          assigntest.assign(utf8bad1, sizeof(utf8bad1) - 1);  // bad
          PEGASUS_TEST_ASSERT(false);
        }
        catch (Exception &)
        {
          // expect an error
        }

        // Test String::assign(char *, Uint32)
        try
        {
          // good, but the last utf-8 char extends past the end
          assigntest.assign(utf8chr, sizeof(utf8chr) - 2);  // bad
          PEGASUS_TEST_ASSERT(false);
        }
        catch (Exception &)
        {
          // expect an error
        }

        //
        // Test passing in good utf-8 with an embedded terminator
        //

        // A utf-8 sequence with a byte zeroed out in an ok spot
        char utf8good1[]    = {
                              '\xCE', '\x99', '\xCE', '\xBF', '\xCF', '\x8D',
                              '\xCE', '\xBD', 'A', '\0', '\xCE', '\xBA',
                              '\xCE', '\xBF', '\xCE', '\xBD', '\xCF', '\x84',
                              '\0'
                            }; // utf8 string with mutliple byte characters

        // Test String(char *)
        try
        {
          // terminator after 5 chars
          String tmp(utf8good1);
          PEGASUS_TEST_ASSERT (tmp.size() == 5);
        }
        catch (Exception &)
        {
          // didn't see that one coming
          PEGASUS_TEST_ASSERT(false);
        }

        // Test String(char *, Uint32)
        try
        {
          // embedded terminator counts as 1 char
          String tmp(utf8good1, sizeof(utf8good1) - 1);
          PEGASUS_TEST_ASSERT (tmp.size() == 10);
        }
        catch (Exception &)
        {
          // didn't see that one coming
          PEGASUS_TEST_ASSERT(false);
        }

        assigntest.clear();

        // Test String::assign(char *)
        try
        {
          // terminator after 5 chars
          assigntest.assign(utf8good1);
          PEGASUS_TEST_ASSERT (assigntest.size() == 5);
        }
        catch (Exception &)
        {
          // didn't see that one coming
          PEGASUS_TEST_ASSERT(false);
        }

        assigntest.clear();

        // Test String::assign(char *, Uint32)
        try
        {
          // embedded terminator counts as 1 char
          assigntest.assign(utf8good1, sizeof(utf8good1) - 1);
          PEGASUS_TEST_ASSERT (assigntest.size() == 10);
        }
        catch (Exception &)
        {
          // didn't see that one coming
          PEGASUS_TEST_ASSERT(false);
        }


        //
        // Casing tests
        //

        String little("the quick brown fox jumped over the lazy dog");
        String    big("THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG");

        String tmpBig = big;
        String tmpLittle = little;

        tmpBig.toLower();
        PEGASUS_TEST_ASSERT(tmpBig == little);

        tmpBig.toUpper();
        PEGASUS_TEST_ASSERT(tmpBig == big);
    }

#if 0
    // The match code has been removed from the String class
    // Test the string match functions
    {
        String abc = "abc";
        String ABC = "ABC";
        PEGASUS_TEST_ASSERT(String::match(abc, "abc"));
        PEGASUS_TEST_ASSERT(String::match(ABC, "ABC"));
        PEGASUS_TEST_ASSERT(!String::match(abc, "ABC"));
        PEGASUS_TEST_ASSERT(!String::match(ABC, "abc"));

        PEGASUS_TEST_ASSERT(String::matchNoCase(abc, "abc"));
        PEGASUS_TEST_ASSERT(String::matchNoCase(ABC, "abc"));
        PEGASUS_TEST_ASSERT(String::matchNoCase(abc, "ABC"));
        PEGASUS_TEST_ASSERT(String::matchNoCase(ABC, "ABc"));

        PEGASUS_TEST_ASSERT(String::match(abc, "???"));
        PEGASUS_TEST_ASSERT(String::match(ABC, "???"));
        PEGASUS_TEST_ASSERT(String::match(abc, "*"));
        PEGASUS_TEST_ASSERT(String::match(ABC, "*"));

        PEGASUS_TEST_ASSERT(String::match(abc, "?bc"));
        PEGASUS_TEST_ASSERT(String::match(abc, "?b?"));
        PEGASUS_TEST_ASSERT(String::match(abc, "??c"));
        PEGASUS_TEST_ASSERT(String::matchNoCase(ABC, "?bc"));
        PEGASUS_TEST_ASSERT(String::matchNoCase(ABC, "?b?"));
        PEGASUS_TEST_ASSERT(String::matchNoCase(ABC, "??c"));


        PEGASUS_TEST_ASSERT(String::match(abc, "*bc"));
        PEGASUS_TEST_ASSERT(String::match(abc, "a*c"));
        PEGASUS_TEST_ASSERT(String::match(abc, "ab*"));
        PEGASUS_TEST_ASSERT(String::match(abc, "a*"));
        // ATTN-RK-P3-20020603: This match code is broken
        //PEGASUS_TEST_ASSERT(String::match(abc, "[axy]bc"));
        PEGASUS_TEST_ASSERT(!String::match(abc, "[xyz]bc"));

        PEGASUS_TEST_ASSERT(!String::match(abc, "def"));
        PEGASUS_TEST_ASSERT(!String::match(abc, "[de]bc"));
        // ATTN-RK-P3-20020603: This match code is broken
        //PEGASUS_TEST_ASSERT(String::match(abc, "a[a-c]c"));
        PEGASUS_TEST_ASSERT(!String::match(abc, "a[d-x]c"));
        // ATTN-RK-P3-20020603: This match code does not yet handle escape chars
        //PEGASUS_TEST_ASSERT(String::match("*test", "\\*test"));

        PEGASUS_TEST_ASSERT(String::match("abcdef123", "*[0-9]"));

        PEGASUS_TEST_ASSERT(String::match("This is a test", "*is*"));
        PEGASUS_TEST_ASSERT(String::matchNoCase("This is a test", "*IS*"));

        PEGASUS_TEST_ASSERT(String::match("Hello", "Hello"));
        PEGASUS_TEST_ASSERT(String::matchNoCase("HELLO", "hello"));
        PEGASUS_TEST_ASSERT(String::match("This is a test", "This is *"));
        PEGASUS_TEST_ASSERT(String::match("This is a test", "* is a test"));
        PEGASUS_TEST_ASSERT(!String::match("Hello", "Goodbye"));

        String tPattern =
            "When in the * of human*e??nts it be?ome[sS] [0-9] nec*";


        try
        {
            String x(reinterpret_cast<const char *>(0));
            cerr <<
                 "Error: Exception not thrown on NULL passed to"
                 " constructor(const char *)"
                << endl;
        }

        catch ( const NullPointer & )
        {
            // This is the exception that should be thrown.
        }

        catch ( ... )
        {
            cerr <<
                "Error: Wrong exception thrown on NULL passed to"
                " constructor(const char *)"
                << endl;
        }


        try
        {
            String x(reinterpret_cast<const Char16 *>(0));
            cerr <<
                "Error: Exception not thrown on NULL passed to"
                " constructor(const Char16 *)"
                << endl;
        }

        catch ( const NullPointer & )
        {
            // This is the exception that should be thrown.
        }

        catch ( ... )
        {
            cerr <<
                "Error: Wrong exception thrown on NULL passed to"
                " constructor(const Char16 *)"
                << endl;
        }


        try
        {
            String x;

            x.assign(reinterpret_cast<const char *>(0));
            cerr <<
                "Error: Exception not thrown on NULL passed to"
                " assign(const char *)"
                << endl;
        }

        catch ( const NullPointer & )
        {
            // This is the exception that should be thrown.
        }

        catch ( ... )
        {
            cerr <<
                "Error: Wrong exception thrown on NULL passed to"
                " assign(const char *)"
                << endl;
        }


        try
        {
            String x;

            x.assign(reinterpret_cast<const Char16 *>(0));
            cerr <<
                "Error: Exception not thrown on NULL passed to"
                " assign(const Char16 *)"
                << endl;
        }

        catch ( const NullPointer & )
        {
            // This is the exception that should be thrown.
        }

        catch ( ... )
        {
            cerr <<
                "Error: Wrong exception thrown on NULL passed to"
                " assign(const Char16 *)"
                << endl;
        }


        try
        {
            String x;

            x.append(reinterpret_cast<const char *>(0));
            cerr <<
                "Error: Exception not thrown on NULL passed to"
                " append(const char *)"
                << endl;
        }

        catch ( const NullPointer & )
        {
            // This is the exception that should be thrown.
        }

        catch ( ... )
        {
            cerr <<
                "Error: Wrong exception thrown on NULL passed to"
                " append(const char *)"
                << endl;
        }


        try
        {
            String x;

            x.append(reinterpret_cast<const Char16 *>(0));
            cerr <<
                "Error: Exception not thrown on NULL passed to"
                " append(const Char16 *)"
                << endl;
        }

        catch ( const NullPointer & )
        {
            // This is the exception that should be thrown.
        }

        catch ( ... )
        {
            cerr <<
                "Error: Wrong exception thrown on NULL passed"
                " to append(const Char16 *)"
                << endl;
        }

        // ATTN-RK-P3-20020603: This match code is broken
        //PEGASUS_TEST_ASSERT(String::match(
        //    "When in the course of human events it becomes 0 necessary",
        //    tPattern));
        //PEGASUS_TEST_ASSERT(String::match(
        //    "When in the xyz of human events it becomes 9 necessary",
        //    tPattern));
        //PEGASUS_TEST_ASSERT(String::match(
        //    "When in the  of human events it becomes 3 necessary",
        //    tPattern));
    }
#endif

    // string()
    {
    String s;
    PEGASUS_TEST_ASSERT(s.size() == 0);
    PEGASUS_TEST_ASSERT(s[0] == '\0');
    }

    // String(const String& s)
    {
    const String s("hello");
    const String t = s;
    PEGASUS_TEST_ASSERT(s.size() == strlen("hello"));
    PEGASUS_TEST_ASSERT(s == "hello");
    PEGASUS_TEST_ASSERT(t.size() == strlen("hello"));
    PEGASUS_TEST_ASSERT(t == "hello");
    }

    // String(const char*)
    {
    const String s("hello");
    PEGASUS_TEST_ASSERT(s.size() == strlen("hello"));
    PEGASUS_TEST_ASSERT(s == "hello");
    }

    // reserve()
    {
    String s;
    s.reserveCapacity(100);
    PEGASUS_TEST_ASSERT(s.size() == 0);
    // PEGASUS_TEST_ASSERT(s.getCapacity() >= 100);

    String t("hello world");
    PEGASUS_TEST_ASSERT(t.size() == strlen("hello world"));
    t.reserveCapacity(500);
    PEGASUS_TEST_ASSERT(t.size() == strlen("hello world"));
    PEGASUS_TEST_ASSERT(t == "hello world");
    }

    // assign(const String&)
    {
    String s("this is a test");
    String t;

    t = s;
    PEGASUS_TEST_ASSERT(s.size() == strlen("this is a test"));
    PEGASUS_TEST_ASSERT(s == "this is a test");
    PEGASUS_TEST_ASSERT(t.size() == strlen("this is a test"));
    PEGASUS_TEST_ASSERT(t == "this is a test");

    s = t;
    PEGASUS_TEST_ASSERT(s.size() == strlen("this is a test"));
    PEGASUS_TEST_ASSERT(s == "this is a test");
    PEGASUS_TEST_ASSERT(t.size() == strlen("this is a test"));
    PEGASUS_TEST_ASSERT(t == "this is a test");
    }

    // assign(const char*, size_t)
    {
    const char MESSAGE[] = "x";
    const size_t LENGTH = sizeof(MESSAGE) - 1;
    String s;
    s.assign(MESSAGE, LENGTH);
    PEGASUS_TEST_ASSERT(s.size() == LENGTH);
    PEGASUS_TEST_ASSERT(s == MESSAGE);

    String t("dummy", 5);
    t.assign(MESSAGE, LENGTH);
    PEGASUS_TEST_ASSERT(t.size() == LENGTH);
    PEGASUS_TEST_ASSERT(t == MESSAGE);
    }

    // assign(const char*)
    {
    const char MESSAGE[] = "x";
    const size_t LENGTH = sizeof(MESSAGE) - 1;
    String s;
    s.assign(MESSAGE);
    PEGASUS_TEST_ASSERT(s.size() == LENGTH);
    PEGASUS_TEST_ASSERT(s == MESSAGE);

    String t("dummy", 5);
    t.assign(MESSAGE);
    PEGASUS_TEST_ASSERT(t.size() == LENGTH);
    PEGASUS_TEST_ASSERT(t == MESSAGE);
    }

    // append(const String&)
    {
    String s;

    s.append(String("xxx"));
    PEGASUS_TEST_ASSERT(s.size() == 3);
    PEGASUS_TEST_ASSERT(s == "xxx");

    s.append(String("yyy"));
    PEGASUS_TEST_ASSERT(s.size() == 6);
    PEGASUS_TEST_ASSERT(s == "xxxyyy");

    s.append(String("zzz"));
    PEGASUS_TEST_ASSERT(s.size() == 9);
    PEGASUS_TEST_ASSERT(s == "xxxyyyzzz");
    }

    // append(const char*)
    {
    String s;

    s.append("xxx");
    PEGASUS_TEST_ASSERT(s.size() == 3);
    PEGASUS_TEST_ASSERT(s == "xxx");

    s.append("yyy");
    PEGASUS_TEST_ASSERT(s.size() == 6);
    PEGASUS_TEST_ASSERT(s == "xxxyyy");

    s.append("zzz");
    PEGASUS_TEST_ASSERT(s.size() == 9);
    PEGASUS_TEST_ASSERT(s == "xxxyyyzzz");
    }

    // append(const char*)
    {
    String s;

    s.append("xxx");
    PEGASUS_TEST_ASSERT(s.size() == 3);
    PEGASUS_TEST_ASSERT(s == "xxx");

    s.append("yyy");
    PEGASUS_TEST_ASSERT(s.size() == 6);
    PEGASUS_TEST_ASSERT(s == "xxxyyy");

    s.append("zzz");
    PEGASUS_TEST_ASSERT(s.size() == 9);
    PEGASUS_TEST_ASSERT(s == "xxxyyyzzz");
    }

    // append(char)
    {
    String s;

    for (int i = 'a'; i <= 'z'; i++)
    {
        Char16 c = i;
        s.append(c);
    }

    PEGASUS_TEST_ASSERT(s.size() == 26);
    PEGASUS_TEST_ASSERT(s == "abcdefghijklmnopqrstuvwxyz");
    }

    // clear()
    {
    String s("abc");
    String t = s;
    String u = s;

    s.clear();
    PEGASUS_TEST_ASSERT(t.size() == 3);
    PEGASUS_TEST_ASSERT(t == "abc");
    PEGASUS_TEST_ASSERT(t[0] == 'a');
    PEGASUS_TEST_ASSERT(u.size() == 3);
    PEGASUS_TEST_ASSERT(u == "abc");
    PEGASUS_TEST_ASSERT(u[0] == 'a');
    PEGASUS_TEST_ASSERT(s.size() == 0);
    PEGASUS_TEST_ASSERT(s[0] == '\0');

    t.clear();
    PEGASUS_TEST_ASSERT(t.size() == 0);
    PEGASUS_TEST_ASSERT(t[0] == '\0');
    PEGASUS_TEST_ASSERT(t == "");
    PEGASUS_TEST_ASSERT(u.size() == 3);
    PEGASUS_TEST_ASSERT(u == "abc");
    PEGASUS_TEST_ASSERT(u[0] == 'a');
    PEGASUS_TEST_ASSERT(s.size() == 0);
    PEGASUS_TEST_ASSERT(s == "");
    PEGASUS_TEST_ASSERT(s[0] == '\0');

    u.clear();
    PEGASUS_TEST_ASSERT(t.size() == 0);
    PEGASUS_TEST_ASSERT(t == "");
    PEGASUS_TEST_ASSERT(t[0] == '\0');
    PEGASUS_TEST_ASSERT(u.size() == 0);
    PEGASUS_TEST_ASSERT(u == "");
    PEGASUS_TEST_ASSERT(u[0] == '\0');
    PEGASUS_TEST_ASSERT(s.size() == 0);
    PEGASUS_TEST_ASSERT(s == "");
    PEGASUS_TEST_ASSERT(s[0] == '\0');
    }

    // c_str()
    {
    String s("abc");
    String t("abc");
    String u("def");
    String v;
    String w("");

    PEGASUS_TEST_ASSERT(s == "abc");
    PEGASUS_TEST_ASSERT(t == "abc");
    PEGASUS_TEST_ASSERT(u == "def");
    PEGASUS_TEST_ASSERT(s == t);
    PEGASUS_TEST_ASSERT(s != u);
    PEGASUS_TEST_ASSERT(v == "");
    PEGASUS_TEST_ASSERT(v[0] == '\0');
    PEGASUS_TEST_ASSERT(v[0] == '\0');
    PEGASUS_TEST_ASSERT(w.size() == 0);
    PEGASUS_TEST_ASSERT(w[0] == '\0');
    PEGASUS_TEST_ASSERT(w[0] == '\0');
    }

    // set(size_t, char)
    {
    String s("abcdefghijklmnopqrstuvwxyz");

    for (int i = 0; i < 26; i++)
        s[i] = toupper(s[i]);

    PEGASUS_TEST_ASSERT(s == "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
    }

    // equal(const String&)
    {
    String t("abc");
    String u("abc");
    String v("def");
    String w("defg");
    String x("");
    String y("");

    PEGASUS_TEST_ASSERT(String::equal(t, t));
    PEGASUS_TEST_ASSERT(String::equal(u, u));
    PEGASUS_TEST_ASSERT(String::equal(v, v));
    PEGASUS_TEST_ASSERT(String::equal(w, w));
    PEGASUS_TEST_ASSERT(String::equal(x, x));
    PEGASUS_TEST_ASSERT(String::equal(y, y));

    PEGASUS_TEST_ASSERT(String::equal(t, u));
    PEGASUS_TEST_ASSERT(String::equal(u, t));

    PEGASUS_TEST_ASSERT(!String::equal(t, v));
    PEGASUS_TEST_ASSERT(!String::equal(t, w));
    PEGASUS_TEST_ASSERT(!String::equal(t, x));
    PEGASUS_TEST_ASSERT(!String::equal(t, y));
    PEGASUS_TEST_ASSERT(!String::equal(v, t));
    PEGASUS_TEST_ASSERT(!String::equal(w, t));
    PEGASUS_TEST_ASSERT(!String::equal(x, t));
    PEGASUS_TEST_ASSERT(!String::equal(y, t));

    PEGASUS_TEST_ASSERT(!String::equal(v, w));
    PEGASUS_TEST_ASSERT(!String::equal(w, v));
    PEGASUS_TEST_ASSERT(String::equal(x, y));
    PEGASUS_TEST_ASSERT(String::equal(y, x));
    }

    // equal(const char*)
    {
    String t("abc");
    String u("abc");
    String v("def");
    String w("defg");
    String x("");
    String y("");

    PEGASUS_TEST_ASSERT(String::equal(t, "abc"));
    PEGASUS_TEST_ASSERT(String::equal(u, "abc"));
    PEGASUS_TEST_ASSERT(String::equal(v, "def"));
    PEGASUS_TEST_ASSERT(String::equal(w, "defg"));
    PEGASUS_TEST_ASSERT(String::equal(x, ""));
    PEGASUS_TEST_ASSERT(String::equal(y, ""));

    PEGASUS_TEST_ASSERT(String::equal(t, "abc"));
    PEGASUS_TEST_ASSERT(String::equal(u, "abc"));

    PEGASUS_TEST_ASSERT(!String::equal(t, "def"));
    PEGASUS_TEST_ASSERT(!String::equal(t, "defg"));
    PEGASUS_TEST_ASSERT(!String::equal(t, ""));
    PEGASUS_TEST_ASSERT(!String::equal(t, ""));
    PEGASUS_TEST_ASSERT(!String::equal(v, "abc"));
    PEGASUS_TEST_ASSERT(!String::equal(w, "abc"));
    PEGASUS_TEST_ASSERT(!String::equal(x, "abc"));
    PEGASUS_TEST_ASSERT(!String::equal(y, "abc"));

    PEGASUS_TEST_ASSERT(!String::equal(v, "defg"));
    PEGASUS_TEST_ASSERT(!String::equal(w, "def"));
    PEGASUS_TEST_ASSERT(String::equal(x, ""));
    PEGASUS_TEST_ASSERT(String::equal(y, ""));
    }

    // equali()
    {
    String s("abc");
    String t("abC");
    String u("ABC");
    String v("xyz");
    String w("");
    String x("");
    PEGASUS_TEST_ASSERT(String::equalNoCase(s, t));
    PEGASUS_TEST_ASSERT(String::equalNoCase(s, u));
    PEGASUS_TEST_ASSERT(!String::equalNoCase(s, v));
    PEGASUS_TEST_ASSERT(String::equalNoCase(w, x));
    PEGASUS_TEST_ASSERT(!String::equalNoCase(w, s));
    PEGASUS_TEST_ASSERT(!String::equalNoCase(w, t));
    PEGASUS_TEST_ASSERT(!String::equalNoCase(w, v));
    }

    {

    String t;
    const char MESSAGE[] = "hello";
    const size_t LENGTH = sizeof(MESSAGE) - 1;
    String s = String(MESSAGE);
    t = s;
    String u = String(t);

    PEGASUS_TEST_ASSERT(t.size() == LENGTH);
    PEGASUS_TEST_ASSERT(t == MESSAGE);
    PEGASUS_TEST_ASSERT(s.size() == LENGTH);
    PEGASUS_TEST_ASSERT(s == MESSAGE);
    PEGASUS_TEST_ASSERT(u.size() == LENGTH);
    PEGASUS_TEST_ASSERT(u == MESSAGE);

    PEGASUS_TEST_ASSERT(t[0] == 'h');
    PEGASUS_TEST_ASSERT(t[1] == 'e');
    PEGASUS_TEST_ASSERT(t[2] == 'l');
    PEGASUS_TEST_ASSERT(t[3] == 'l');
    PEGASUS_TEST_ASSERT(t[4] == 'o');
    PEGASUS_TEST_ASSERT(t[5] == '\0');

    t.append(" world");
    PEGASUS_TEST_ASSERT(t.size() == strlen("hello world"));
    PEGASUS_TEST_ASSERT(t == "hello world");
    PEGASUS_TEST_ASSERT(s != "hello world");
    PEGASUS_TEST_ASSERT(s == "hello");
    PEGASUS_TEST_ASSERT(s.size() == strlen("hello"));

    t[0] = 'x';
    PEGASUS_TEST_ASSERT(t == "xello world");
    }

    // remove()
    {
    String s("abcXYZdefLMNOP");

    s.remove(0,0);
    PEGASUS_TEST_ASSERT(s.size() == 14);
    PEGASUS_TEST_ASSERT(s == "abcXYZdefLMNOP");

    s.remove(0, 3);
    PEGASUS_TEST_ASSERT(s.size() == 11);
    PEGASUS_TEST_ASSERT(s == "XYZdefLMNOP");

    s.remove(3, 3);
    PEGASUS_TEST_ASSERT(s.size() == 8);
    PEGASUS_TEST_ASSERT(s == "XYZLMNOP");

    s.remove(7, 1);
    PEGASUS_TEST_ASSERT(s.size() == 7);
    PEGASUS_TEST_ASSERT(s == "XYZLMNO");

    s.remove(0, 1);
    PEGASUS_TEST_ASSERT(s.size() == 6);
    PEGASUS_TEST_ASSERT(s == "YZLMNO");

    s.remove(2, PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(s.size() == 2);
    PEGASUS_TEST_ASSERT(s == "YZ");

    s.remove(2, 0);
    PEGASUS_TEST_ASSERT(s.size() == 2);
    PEGASUS_TEST_ASSERT(s == "YZ");

    s.remove(1, 1);
    PEGASUS_TEST_ASSERT(s.size() == 1);
    PEGASUS_TEST_ASSERT(s == "Y");

    s.remove(0, 1);
    PEGASUS_TEST_ASSERT(s.size() == 0);
    PEGASUS_TEST_ASSERT(s == "");
    PEGASUS_TEST_ASSERT(s[0] == '\0');

    s.remove(0,0);
    PEGASUS_TEST_ASSERT(s.size() == 0);
    PEGASUS_TEST_ASSERT(s == "");
    PEGASUS_TEST_ASSERT(s[0] == '\0');
    }

    // subString()
    {
    String s("one two three");
    PEGASUS_TEST_ASSERT(s.subString(0) == "one two three");
    PEGASUS_TEST_ASSERT(s.subString(0, 3) == "one");
    PEGASUS_TEST_ASSERT(s.subString(4, 3) == "two");
    PEGASUS_TEST_ASSERT(s.subString(8, 5) == "three");
    PEGASUS_TEST_ASSERT(s.subString(0, 0) == "");
    PEGASUS_TEST_ASSERT(s.subString(13, 0) == "");
    }

    // Overflow
    bool caught_bad_alloc = false;
    try
    {
    String s("junk", Uint32(0xFFFFFFFF));
    }
    catch(...)
    {
    caught_bad_alloc = true;
    }
    PEGASUS_TEST_ASSERT(caught_bad_alloc);

    // Added to test funtionality of String(const String& str, Uint32 n)
    // for memory overflow.
    Boolean caughtBadAlloc = false;
    try
    {
        String s("abc", 0xFFFF0000);   //to check for alloc
    }
    catch(const PEGASUS_STD(bad_alloc)&)
    {
        caughtBadAlloc = true;
    }

    // Added to test funtionality of
    // void reserveCapacity(Uint32 capacity) for memory overflow.
    caughtBadAlloc = false;
    try
    {
        String s;
        s.reserveCapacity(0xFFFF0000);   //to check for _reserve
    }
    catch (const PEGASUS_STD(bad_alloc)&)
    {
        caughtBadAlloc = true;
    }
    PEGASUS_TEST_ASSERT(caughtBadAlloc);

    // Added to test funtionality of
    // String& append(const char* str, Uint32 size) for memory overflow.
    caughtBadAlloc = false;
    try
    {
        String s;
        s.append("xxx", 0xFFFF0000);         //to check for _reserve
    }
    catch (const PEGASUS_STD(bad_alloc)&)
    {
        caughtBadAlloc = true;
    }
    PEGASUS_TEST_ASSERT(caughtBadAlloc);

    // Added to test funtionality of
    // String& append(const Char16* str, Uint32 n) for memory overflow.
    caughtBadAlloc = false;
    try
    {
        String s;
        s.append((Char16 *)"xxx", 0xFFFF0000); //to check for _reserve
    }
    catch (const PEGASUS_STD(bad_alloc)&)
    {
        caughtBadAlloc = true;
    }
    PEGASUS_TEST_ASSERT(caughtBadAlloc);

    // Added to test funtionality of
    // String& assign(const char* str, Uint32 n) for memory overflow.
    caughtBadAlloc = false;
    try
    {
        String s;
        s.assign("xxx", 0xFFFF0000);               //to check for alloc
    }
    catch (const PEGASUS_STD(bad_alloc)&)
    {
    caughtBadAlloc = true;
    }
    PEGASUS_TEST_ASSERT(caughtBadAlloc);

    // Added to test funtionality of
    // String& assign(const Char16* str, Uint32 n) for memory overflow.
    caughtBadAlloc = false;
    try
    {
        String s;
        s.assign((Char16 *)"xxx", 0xFFFF0000);   //to check for alloc
    }
    catch (const PEGASUS_STD(bad_alloc)&)
    {
        caughtBadAlloc = true;
    }
    PEGASUS_TEST_ASSERT(caughtBadAlloc);

    // Tests for the dump of a bad strings.

    // 40 good chars, bad char, 10 trailing chars.
    //    Testing the full range of printed data.

    caughtBadAlloc = false;
    try
    {
        String s1("1234567890123456789012345678901234567890""\xFF""1234567890");
    }
    catch ( Exception& ex )
    {
        caughtBadAlloc = true;
        PEGASUS_TEST_ASSERT(
            strstr((const char*)ex.getMessage().getCString(),
                ": 1234567890123456789012345678901234567890"
                    " 0xFF 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x39 0x30")
            != 0);

    }
    PEGASUS_TEST_ASSERT(caughtBadAlloc);

    // 7 good chars, bad char, 7 trailing chars.
    // Testing reduced number of chars arround the bad char.

    caughtBadAlloc = false;
    try
    {
        String s1("0123456""\xAA""0123456");
    }
    catch ( Exception& ex )
    {
        caughtBadAlloc = true;
        PEGASUS_TEST_ASSERT(
            strstr((const char*)ex.getMessage().getCString(),
                ": 0123456 0xAA 0x30 0x31 0x32 0x33 0x34 0x35 0x36")
            != 0);

    }
    PEGASUS_TEST_ASSERT(caughtBadAlloc);

    // No good chars, bad char , 20 trailing chars
    // Testing no good chars, bad char at beginning,
    // more trailing chars available then printed.

    caughtBadAlloc = false;
    try
    {
        String s1("\xDD""0123456789012345679");
    }
    catch ( Exception& ex )
    {
        caughtBadAlloc = true;
        PEGASUS_TEST_ASSERT(
            strstr((const char*)ex.getMessage().getCString(),
                ":  0xDD 0x30 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x39")
            != 0);

    }
    PEGASUS_TEST_ASSERT(caughtBadAlloc);

    // 50 good chars ( more the printed ), bad char as last char,
    // no trailing chars.

    caughtBadAlloc = false;
    try
    {
        String s1("AAAAAAAAAA0123456789012345678901234567890123456789""\xBB");
    }
    catch ( Exception& ex )
    {
        caughtBadAlloc = true;
        PEGASUS_TEST_ASSERT(
            strstr((const char*)ex.getMessage().getCString(),
                ": 0123456789012345678901234567890123456789 0xBB")
            != 0);

    }
    PEGASUS_TEST_ASSERT(caughtBadAlloc);

    // no good chars, bad char as the only char, no trailing chars.

    caughtBadAlloc = false;
    try
    {
        String s1("\x80");
    }
    catch ( Exception& ex )
    {
        caughtBadAlloc = true;
        PEGASUS_TEST_ASSERT(
            strstr((const char*)ex.getMessage().getCString(),":  0x80") != 0);
    }
    PEGASUS_TEST_ASSERT(caughtBadAlloc);

    cout << argv[0] << " +++++ passed all tests" << endl;

    char* p = (char*)operator new(88888);
    operator delete(p);

    return 0;
}
Пример #25
0
String CIMObjectPath::_toStringCanonical() const
{
    CIMObjectPath ref;
    *ref._rep = *this->_rep;

    // Normalize hostname by changing to lower case
    ref._rep->_host.toLower(); // ICU_TODO:

    // Normalize namespace by changing to lower case
    if (!ref._rep->_nameSpace.isNull())
    {
        String nameSpaceLower = ref._rep->_nameSpace.getString();
        nameSpaceLower.toLower(); // ICU_TODO:
        ref._rep->_nameSpace = nameSpaceLower;
    }

    // Normalize class name by changing to lower case
    if (!ref._rep->_className.isNull())
    {
        String classNameLower = ref._rep->_className.getString();
        classNameLower.toLower(); // ICU_TODO:
        ref._rep->_className = classNameLower;
    }

    for (Uint32 i = 0, n = ref._rep->_keyBindings.size(); i < n; i++)
    {
        // Normalize key binding name by changing to lower case
        if (!ref._rep->_keyBindings[i]._rep->_name.isNull())
        {
            String keyBindingNameLower =
                ref._rep->_keyBindings[i]._rep->_name.getString();
            keyBindingNameLower.toLower(); // ICU_TODO:
            ref._rep->_keyBindings[i]._rep->_name = keyBindingNameLower;
        }

        // Normalize the key value
        switch (ref._rep->_keyBindings[i]._rep->_type)
        {
        case CIMKeyBinding::REFERENCE:
            try
            {
                // Convert reference to CIMObjectPath and recurse
                ref._rep->_keyBindings[i]._rep->_value =
                    CIMObjectPath(ref._rep->_keyBindings[i]._rep->_value).
                        _toStringCanonical();
            }
            catch (Exception&)
            {
                // Leave value unchanged if the CIMObjectPath parsing fails
            }
            break;
        case CIMKeyBinding::BOOLEAN:
            // Normalize the boolean string by changing to lower case
            ref._rep->_keyBindings[i]._rep->_value.toLower(); // ICU_TODO:
            break;
        case CIMKeyBinding::NUMERIC:
            // Normalize the numeric string by converting to integer and back
            Uint64 uValue;
            Sint64 sValue;
            // First try converting to unsigned integer
            if (StringConversion::stringToUnsignedInteger(
                    ref._rep->_keyBindings[i]._rep->_value.getCString(),
                        uValue))
            {
                char buffer[32];  // Should need 21 chars max
                sprintf(buffer, "%" PEGASUS_64BIT_CONVERSION_WIDTH "u", uValue);
                ref._rep->_keyBindings[i]._rep->_value = String(buffer);
            }
            // Next try converting to signed integer
            else if (StringConversion::stringToSignedInteger(
                         ref._rep->_keyBindings[i]._rep->_value.getCString(),
                             sValue))
            {
                char buffer[32];  // Should need 21 chars max
                sprintf(buffer, "%" PEGASUS_64BIT_CONVERSION_WIDTH "d", sValue);
                ref._rep->_keyBindings[i]._rep->_value = String(buffer);
            }
            // Leave value unchanged if it cannot be converted to an integer
            break;
        default:  // CIMKeyBinding::STRING
            // No normalization required for STRING
            break;
        }
    }

    // Note: key bindings are sorted when set in the CIMObjectPath

    return ref.toString();
}
Пример #26
0
  void createParamFile_(ostream& os)
  {
    os << "# comet_version " << getStringOption_("comet_version") << "\n";               //required as first line in the param file
    os << "# Comet MS/MS search engine parameters file.\n";
    os << "# Everything following the '#' symbol is treated as a comment.\n";
    os << "database_name = " << getStringOption_("database") << "\n";
    os << "decoy_search = " << 0 << "\n"; // 0=no (default), 1=concatenated search, 2=separate search
    os << "num_threads = " << getIntOption_("threads") << "\n";  // 0=poll CPU to set num threads; else specify num threads directly (max 64)

    // masses
    map<String,int> precursor_error_units;
    precursor_error_units["amu"] = 0;
    precursor_error_units["mmu"] = 1;
    precursor_error_units["ppm"] = 2;

    map<string,int> isotope_error;
    isotope_error["off"] = 0;
    isotope_error["-1/0/1/2/3"] = 1;
    isotope_error["-8/-4/0/4/8"] = 2;

    os << "peptide_mass_tolerance = " << getDoubleOption_("precursor_mass_tolerance") << "\n";
    os << "peptide_mass_units = " << precursor_error_units[getStringOption_("precursor_error_units")] << "\n";                  // 0=amu, 1=mmu, 2=ppm
    os << "mass_type_parent = " << 1 << "\n";                    // 0=average masses, 1=monoisotopic masses
    os << "mass_type_fragment = " << 1 << "\n";                  // 0=average masses, 1=monoisotopic masses
    os << "precursor_tolerance_type = " << 0 << "\n";            // 0=MH+ (default), 1=precursor m/z; only valid for amu/mmu tolerances
    os << "isotope_error = " << isotope_error[getStringOption_("isotope_error")] << "\n";                      // 0=off, 1=on -1/0/1/2/3 (standard C13 error), 2= -8/-4/0/4/8 (for +4/+8 labeling)

    // search enzyme

    String enzyme_name = getStringOption_("enzyme");
    String enzyme_number = String(ProteaseDB::getInstance()->getEnzyme(enzyme_name)->getCometID());

    map<string,int> num_enzyme_termini;
    num_enzyme_termini["semi"] = 1;
    num_enzyme_termini["fully"] = 2;
    num_enzyme_termini["C-term unspecific"] = 8;
    num_enzyme_termini["N-term unspecific"] = 9;

    os << "search_enzyme_number = " << enzyme_number << "\n";                // choose from list at end of this params file
    os << "num_enzyme_termini = " << num_enzyme_termini[getStringOption_("num_enzyme_termini")] << "\n";                  // 1 (semi-digested), 2 (fully digested, default), 8 C-term unspecific , 9 N-term unspecific
    os << "allowed_missed_cleavage = " << getIntOption_("allowed_missed_cleavages") << "\n";             // maximum value is 5; for enzyme search

    // Up to 9 variable modifications are supported
    // format:  <mass> <residues> <0=variable/else binary> <max_mods_per_peptide> <term_distance> <n/c-term> <required>
    //     e.g. 79.966331 STY 0 3 -1 0 0
    vector<String> variable_modifications_names = getStringList_("variable_modifications");
    vector<ResidueModification> variable_modifications = getModifications_(variable_modifications_names);
    if (variable_modifications.size() > 9)
    {
      throw OpenMS::Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "Error: Comet only supports 9 variable modifications. " + String(variable_modifications.size()) + " provided.");
    }

    int max_variable_mods_in_peptide = getIntOption_("max_variable_mods_in_peptide");
    Size var_mod_index = 0;

    // write out user specified modifications
    for (; var_mod_index < variable_modifications.size(); ++var_mod_index)
    {
      const ResidueModification mod = variable_modifications[var_mod_index];
      double mass = mod.getDiffMonoMass();
      String residues = mod.getOrigin();
      //TODO support binary groups, e.g. for SILAC
      int binary_group = 0;
      //TODO support mod-specific limit (default for now is the overall max per peptide)
      int max_current_mod_per_peptide = max_variable_mods_in_peptide;
      //TODO support term-distances?
      int term_distance = -1;
      int nc_term = 0;

      //TODO support agglomeration of Modifications to same AA. Watch out for nc_term value then.
      if (mod.getTermSpecificity() == ResidueModification::C_TERM)
      {
        residues = "c";
        term_distance = 0;
        // Since users need to specify mods that apply to multiple residues/terms separately
        // 3 and -1 should be equal for now.
        nc_term = 3;
      }
      else if (mod.getTermSpecificity() == ResidueModification::N_TERM)
      {
        residues = "n";
        term_distance = 0;
        // Since users need to specify mods that apply to multiple residues/terms separately
        // 2 and -1 should be equal for now.
        nc_term = 2;
      }
      else if (mod.getTermSpecificity() == ResidueModification::PROTEIN_N_TERM) // not yet available
      {
        term_distance = 0;
        nc_term = 0;
      }
      else if (mod.getTermSpecificity() == ResidueModification::PROTEIN_C_TERM) // not yet available
      {
        term_distance = 0;
        nc_term = 1;
      }

      //TODO support required variable mods
      bool required = false;

      os << "variable_mod0" << var_mod_index+1 << " = " << mass << " " << residues << " " << binary_group << " " << max_current_mod_per_peptide << " " << term_distance << " " << nc_term << " " << required << "\n";
    }

    // fill remaining modification slots (if any) in Comet with "no modification"
    for (; var_mod_index < 9; ++var_mod_index)
    {
      os << "variable_mod0" << var_mod_index+1 << " = " << "0.0 X 0 3 -1 0 0" << "\n";
    }

    os << "max_variable_mods_in_peptide = " << getIntOption_("max_variable_mods_in_peptide") << "\n";
    os << "require_variable_mod = " << (int) (getStringOption_("require_variable_mod") == "true") << "\n";

    // fragment ion defaults
    // ion trap ms/ms:  1.0005 tolerance, 0.4 offset (mono masses), theoretical_fragment_ions = 1
    // high res ms/ms:    0.02 tolerance, 0.0 offset (mono masses), theoretical_fragment_ions = 0

    String instrument = getStringOption_("instrument");
    double bin_tol = getDoubleOption_("fragment_bin_tolerance");
    double bin_offset = getDoubleOption_("fragment_bin_offset");
    if (instrument == "low_res" && (bin_tol < 0.9 || bin_offset <= 0.2))
    {
      LOG_WARN << "Fragment bin size or tolerance is quite low for low res instruments." << "\n";
    }
    else if (instrument == "high_res" && (bin_tol > 0.2 || bin_offset > 0.1))
    {
      LOG_WARN << "Fragment bin size or tolerance is quite high for high res instruments." << "\n";
    };

    os << "fragment_bin_tol = " << bin_tol << "\n";               // binning to use on fragment ions
    os << "fragment_bin_offset = " << bin_offset  << "\n";              // offset position to start the binning (0.0 to 1.0)
    os << "theoretical_fragment_ions = " << (int)(instrument == "low_res") << "\n";           // 0=use flanking bin, 1=use M bin only
    os << "use_A_ions = " << (int)(getStringOption_("use_A_ions")=="true") << "\n";
    os << "use_B_ions = " << (int)(getStringOption_("use_B_ions")=="true") << "\n";
    os << "use_C_ions = " << (int)(getStringOption_("use_C_ions")=="true") << "\n";
    os << "use_X_ions = " << (int)(getStringOption_("use_X_ions")=="true") << "\n";
    os << "use_Y_ions = " << (int)(getStringOption_("use_Y_ions")=="true") << "\n";
    os << "use_Z_ions = " << (int)(getStringOption_("use_Z_ions")=="true") << "\n";
    os << "use_NL_ions = " << (int)(getStringOption_("use_NL_ions")=="true") << "\n";                         // 0=no, 1=yes to consider NH3/H2O neutral loss peaks

    // output
    os << "output_sqtstream = " << 0 << "\n";                    // 0=no, 1=yes  write sqt to standard output
    os << "output_sqtfile = " << 0 << "\n";                      // 0=no, 1=yes  write sqt file
    os << "output_txtfile = " << 0 << "\n";                     // 0=no, 1=yes  write tab-delimited txt file
    os << "output_pepxmlfile = " << 1 << "\n";                   // 0=no, 1=yes  write pep.xml file

    os << "output_percolatorfile = " << !getStringOption_("pin_out").empty() << "\n";              // 0=no, 1=yes  write Percolator tab-delimited input file
    os << "output_outfiles = " <<  0 << "\n";                    // 0=no, 1=yes  write .out files
    os << "print_expect_score = " << 1 << "\n";                  // 0=no, 1=yes to replace Sp with expect in out & sqt
    os << "num_output_lines = " << getIntOption_("num_hits") << "\n";                    // num peptide results to show
    os << "show_fragment_ions = " << 0 << "\n";                  // 0=no, 1=yes for out files only
    os << "sample_enzyme_number = " << enzyme_number << "\n";                // Sample enzyme which is possibly different than the one applied to the search.

    // mzXML parameters
    map<string,int> override_charge;
    override_charge["keep any known"] = 0;
    override_charge["ignore known"] = 1;
    override_charge["ignore outside range"] = 2;
    override_charge["keep known search unknown"] = 3;

    int precursor_charge_min(0), precursor_charge_max(0);
    if (!parseRange_(getStringOption_("precursor_charge"), precursor_charge_min, precursor_charge_max))
    {
      LOG_INFO << "precursor_charge range not set. Defaulting to 0:0 (disable charge filtering)." << endl;
    }

    os << "scan_range = " << "0 0" << "\n";                        // start and scan scan range to search; 0 as 1st entry ignores parameter
    os << "precursor_charge = " << precursor_charge_min << " " << precursor_charge_max << "\n";                  // precursor charge range to analyze; does not override any existing charge; 0 as 1st entry ignores parameter
    os << "override_charge = " << override_charge[getStringOption_("override_charge")] << "\n";                     // 0=no, 1=override precursor charge states, 2=ignore precursor charges outside precursor_charge range, 3=see online
    os << "ms_level = " << getIntOption_("ms_level") << "\n";                            // MS level to analyze, valid are levels 2 (default) or 3
    os << "activation_method = " << getStringOption_("activation_method") << "\n";                 // activation method; used if activation method set; allowed ALL, CID, ECD, ETD, PQD, HCD, IRMPD

    // misc parameters
    double digest_mass_range_min(600.0), digest_mass_range_max(5000.0);
    if (!parseRange_(getStringOption_("digest_mass_range"), digest_mass_range_min, digest_mass_range_max))
    {
      LOG_INFO << "digest_mass_range not set. Defaulting to 600.0 5000.0." << endl;
    }

    os << "digest_mass_range = " << digest_mass_range_min << " " << digest_mass_range_max << "\n";        // MH+ peptide mass range to analyze
    os << "num_results = " << 100 << "\n";                       // number of search hits to store internally
    os << "skip_researching = " << 1 << "\n";                    // for '.out' file output only, 0=search everything again (default), 1=don't search if .out exists
    os << "max_fragment_charge = " << getIntOption_("max_fragment_charge") << "\n";                 // set maximum fragment charge state to analyze (allowed max 5)
    os << "max_precursor_charge = " << getIntOption_("max_precursor_charge") << "\n";                // set maximum precursor charge state to analyze (allowed max 9)
    os << "nucleotide_reading_frame = " << 0 << "\n";            // 0=proteinDB, 1-6, 7=forward three, 8=reverse three, 9=all six
    os << "clip_nterm_methionine = " << (int)(getStringOption_("clip_nterm_methionine")=="true") << "\n";              // 0=leave sequences as-is; 1=also consider sequence w/o N-term methionine
    os << "spectrum_batch_size = " << getIntOption_("spectrum_batch_size") << "\n";                 // max. // of spectra to search at a time; 0 to search the entire scan range in one loop
    os << "decoy_prefix = " << "--decoysearch-not-used--" << "\n";                 // decoy entries are denoted by this string which is pre-pended to each protein accession
    os << "output_suffix = " << "" << "\n";                      // add a suffix to output base names i.e. suffix "-C" generates base-C.pep.xml from base.mzXML input
    os << "mass_offsets = " << ListUtils::concatenate(getDoubleList_("mass_offsets"), " ") << "\n"; // one or more mass offsets to search (values subtracted from deconvoluted precursor mass)

    // spectral processing
    map<string,int> remove_precursor_peak;
    remove_precursor_peak["no"] = 0;
    remove_precursor_peak["yes"] = 1;
    remove_precursor_peak["charge_reduced"] = 2;
    remove_precursor_peak["phosphate_loss"] = 3;

    double clear_mz_range_min(0.0), clear_mz_range_max(0.0);
    if (!parseRange_(getStringOption_("clear_mz_range"), clear_mz_range_min, clear_mz_range_max))
    {
      LOG_INFO << "clear_mz_range not set. Defaulting to 0:0 (disable m/z filter)." << endl;
    }

    os << "minimum_peaks = " << getIntOption_("minimum_peaks") << "\n";                      // required minimum number of peaks in spectrum to search (default 10)
    os << "minimum_intensity = " << getDoubleOption_("minimum_intensity") << "\n";                   // minimum intensity value to read in
    os << "remove_precursor_peak = " << remove_precursor_peak[getStringOption_("remove_precursor_peak")] << "\n";               // 0=no, 1=yes, 2=all charge reduced precursor peaks (for ETD)
    os << "remove_precursor_tolerance = " << getDoubleOption_("remove_precursor_tolerance") << "\n";        // +- Da tolerance for precursor removal
    os << "clear_mz_range = " << clear_mz_range_min << " " << clear_mz_range_max << "\n";                // for iTRAQ/TMT type data; will clear out all peaks in the specified m/z range


    // write fixed modifications - if not specified residue parameter is zero
    // Aminoacid:
    //      add_AA.OneletterCode_AA.ThreeLetterCode = xxx
    // Terminus:
    //      add_N/Cterm_peptide = xxx       protein not available yet
    vector<String> fixed_modifications_names = getStringList_("fixed_modifications");
    vector<ResidueModification> fixed_modifications = getModifications_(fixed_modifications_names);
    // Comet sets Carbamidometyl (C) as modification as default even if not specified
    // Therefor there is the need to set it to 0 if not set as flag
    if (fixed_modifications.empty())
    {
      os << "add_C_cysteine = 0.0000" << endl;
    }
    else
    {
      for (vector<ResidueModification>::const_iterator it = fixed_modifications.begin(); it != fixed_modifications.end(); ++it)
      {
        String AA = it->getOrigin();
        if ((AA!="N-term") && (AA!="C-term"))
        {
          const Residue* r = ResidueDB::getInstance()->getResidue(AA);
          String name = r->getName();
          os << "add_" << r->getOneLetterCode() << "_" << name.toLower() << " = " << it->getDiffMonoMass() << endl;
        }
        else
        {
          os << "add_" << AA.erase(1,1) << "_peptide = " << it->getDiffMonoMass() << endl;
        }
      }
    }

    //TODO register cut_before and cut_after in Enzymes.xml plus datastructures to add all our Enzymes with our names instead.
    // COMET_ENZYME_INFO _must_ be at the end of this parameters file
    os << "[COMET_ENZYME_INFO]" << "\n";
    os << "0.  No_enzyme              0      -           -" << "\n";
    os << "1.  Trypsin                1      KR          P" << "\n";
    os << "2.  Trypsin/P              1      KR          -" << "\n";
    os << "3.  Lys_C                  1      K           P" << "\n";
    os << "4.  Lys_N                  0      K           -" << "\n";
    os << "5.  Arg_C                  1      R           P" << "\n";
    os << "6.  Asp_N                  0      D           -" << "\n";
    os << "7.  CNBr                   1      M           -" << "\n";
    os << "8.  Glu_C                  1      DE          P" << "\n";
    os << "9.  PepsinA                1      FL          P" << "\n";
    os << "10. Chymotrypsin           1      FWYL        P" << "\n";
  }
Пример #27
0
// read in a list linking IPs, subnets & IP ranges to filter groups
bool IPList::readIPMelangeList(const char *filename)
{
	// load in the list file
	std::ifstream input ( filename );
	if (!input) {
		if (!is_daemonised) {
			std::cerr << "Error reading file (does it exist?): " << filename << std::endl;
		}
		syslog(LOG_ERR, "%s%s","Error reading file (does it exist?): ",filename);
		return false;
	}

	// compile regexps for determining whether a list entry is an IP, a subnet (IP + mask), or a range
	RegExp matchIP, matchSubnet, matchRange;
#ifdef HAVE_PCRE
	matchIP.comp("^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$");
	matchSubnet.comp("^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}/\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$");
	matchRange.comp("^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}-\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$");
#else
	matchIP.comp("^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$");
	matchSubnet.comp("^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}/[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$");
	matchRange.comp("^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}-[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$");
#endif

	// read in the file
	String line;
	char buffer[ 2048 ];
	while (input) {
		if (!input.getline(buffer, sizeof( buffer ))) {
			break;
		}
		// ignore comments
		if (buffer[0] == '#')
			continue;
		// ignore blank lines
		if (strlen(buffer) < 7)
			continue;
		line = buffer;
#ifdef DGDEBUG
		std::cout << "line: " << line << std::endl;
#endif
		// store the IP address (numerically, not as a string) and filter group in either the IP list, subnet list or range list
		if (matchIP.match(line.toCharArray())) {
			struct in_addr address;
			if (inet_aton(line.toCharArray(), &address)) {
				uint32_t addr = ntohl(address.s_addr);
				iplist.push_back(addr);
			}
		}
		else if (matchSubnet.match(line.toCharArray())) {
			struct in_addr address;
			struct in_addr addressmask;
			String subnet(line.before("/"));
			String mask(line.after("/"));
			if (inet_aton(subnet.toCharArray(), &address) && inet_aton(mask.toCharArray(), &addressmask)) {
				ipl_subnetstruct s;
				uint32_t addr = ntohl(address.s_addr);
				s.mask = ntohl(addressmask.s_addr);
				// pre-mask the address for quick comparison
				s.maskedaddr = addr & s.mask;
				ipsubnetlist.push_back(s);
			}
		}
		else if (matchRange.match(line.toCharArray())) {
			struct in_addr addressstart;
			struct in_addr addressend;
			String start(line.before("-"));
			String end(line.after("-"));
			if (inet_aton(start.toCharArray(), &addressstart) && inet_aton(end.toCharArray(), &addressend)) {
				ipl_rangestruct r;
				r.startaddr = ntohl(addressstart.s_addr);
				r.endaddr = ntohl(addressend.s_addr);
				iprangelist.push_back(r);
			}
		}
		// hmmm. the line didn't match any of our regular expressions.
		// assume it's a hostname.
		else {
			line.toLower();
			hostlist.push_back(line);
		}
	}
	input.close();
#ifdef DGDEBUG
	std::cout << "starting sort" << std::endl;
#endif
	std::sort(iplist.begin(), iplist.end());
	std::sort(hostlist.begin(), hostlist.end());
#ifdef DGDEBUG
	std::cout << "sort complete" << std::endl;
	std::cout << "ip list dump:" << std::endl;
	std::vector<uint32_t>::iterator i = iplist.begin();
	while (i != iplist.end()) {
		std::cout << "IP: " << *i << std::endl;
		++i;
	}
	std::cout << "subnet list dump:" << std::endl;
	std::list<ipl_subnetstruct>::iterator j = ipsubnetlist.begin();
	while (j != ipsubnetlist.end()) {
		std::cout << "Masked IP: " << j->maskedaddr << " Mask: " << j->mask << std::endl;
		++j;
	}
	std::cout << "range list dump:" << std::endl;
	std::list<ipl_rangestruct>::iterator k = iprangelist.begin();
	while (k != iprangelist.end()) {
		std::cout << "Start IP: " << k->startaddr << " End IP: " << k->endaddr << std::endl;
		++k;
	}
	std::cout << "host list dump:" << std::endl;
	std::vector<String>::iterator l = hostlist.begin();
	while (l != hostlist.end()) {
		std::cout << "Hostname: " << *l << std::endl;
		++l;
	}
#endif
	return true;
}
Пример #28
0
void ProviderManagerMap::initialize()
{
    String libExt = FileSystem::getDynamicLibraryExtension();
    // first add the default:

    ProvMgrIfcInfo defaultPMEntry;
    defaultPMEntry.path.clear();
    defaultPMEntry.ifcName = "C++Default";
    defaultPMEntry.ifcVersions.append(String("2.1.0"));
    defaultPMEntry.ifcVersions.append(String("2.2.0"));
    defaultPMEntry.ifcVersions.append(String("2.3.0"));
    defaultPMEntry.ifcVersions.append(String("2.5.0"));
    defaultPMEntry.ifcVersions.append(String("2.6.0"));
    defaultPMEntry.ifcVersions.append(String("2.9.0"));
    _pmArray.append(defaultPMEntry);

    // now check for plugins

    String dirName = ConfigManager::getInstance()->getCurrentValue(
            "providerManagerDir");
    dirName = ConfigManager::getHomedPath(dirName);

    PEG_TRACE((TRC_PROVIDERMANAGER, Tracer::LEVEL3,
        "Looking for ProviderManagers in %s.",
        (const char*)dirName.getCString()));

    // check to make sure that this ifc type is handled by one of the
    // provider managers in the directory
    String testname = String("providermanager")+libExt;
    for (Dir dir(dirName); dir.more(); dir.next())
    {
        String filename = dir.getName();
        String lowerFilename = filename;
        lowerFilename.toLower();
        if ((lowerFilename.subString(lowerFilename.size()-testname.size()) ==
                 testname) &&
            (lowerFilename !=
                 FileSystem::buildLibraryFileName("defaultprovidermanager")) &&
            (lowerFilename !=
                 FileSystem::buildLibraryFileName("pegprovidermanager")))
        {
            String fullPath = dirName + "/" + filename;
            // found a file... assume it's a ProviderManager library
            PEG_TRACE((TRC_PROVIDERMANAGER, Tracer::LEVEL4,
                "Found file %s. Checking to see if it is a ProviderManager.",
                (const char*)fullPath.getCString()));
            DynamicLibrary dl(fullPath);
            if (!dl.load())
            {
                Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER,
                    Logger::SEVERE,
                    MessageLoaderParms(
                        "Server.ProviderRegistrationManager.ProviderManagerMap."
                            "LOAD_ERROR",
                        "Error loading library $0: $1.",
                        fullPath, dl.getLoadErrorMessage()));
                continue;    // to the next file
            }

            Uint32 (*get_peg_ver)() =
                (Uint32(*)()) dl.getSymbol("getPegasusVersion");

            if (get_peg_ver == 0)
            {
                Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER,
                    Logger::SEVERE,
                    MessageLoaderParms(
                        "Server.ProviderRegistrationManager.ProviderManagerMap."
                            "MISSING_GET_PG_VERSION",
                        "Library $0 does not contain expected function "
                            "'getPegasusVersion'.",
                        fullPath));
                continue;
            }

            Uint32 peg_ver = get_peg_ver();
            if (peg_ver != PEGASUS_VERSION_NUMBER)
            {
                Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER,
                    Logger::SEVERE,
                    MessageLoaderParms(
                        "Server.ProviderRegistrationManager.ProviderManagerMap."
                            "WRONG_VERSION",
                        "Provider Manager $0 returned Pegasus "
                            "version $1.  Expected $2.",
                        fullPath, peg_ver, PEGASUS_VERSION_NUMBER));
                continue;
            }

            const char** (*get_ifc)() = (const char**(*)()) dl.getSymbol(
                "getProviderManagerInterfaceNames");
            const char** (*get_ver)(const char *) =
                (const char**(*)(const char *)) dl.getSymbol(
                    "getProviderManagerInterfaceVersions");
            if (get_ifc == 0)
            {
                Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER,
                    Logger::SEVERE,
                    MessageLoaderParms(
                        "Server.ProviderRegistrationManager.ProviderManagerMap."
                            "MISSING_GET_IFC_NAMES",
                        "Provider Manager $0 does not contain expected "
                            "function 'getProviderManagerInterfaceNames'",
                        fullPath));
                continue;    // to the next file
            }
            if (get_ver == 0)
            {
                Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER,
                    Logger::SEVERE,
                    MessageLoaderParms(
                        "Server.ProviderRegistrationManager.ProviderManagerMap."
                            "MISSING_GET_IFC_VERSIONS",
                        "Provider Manager $0 does not contain expected "
                            "function 'getProviderManagerInterfaceVersions'",
                        fullPath));
                continue;    // to the next file
            }

            const char ** ifcNames = get_ifc();
            if ((ifcNames!=NULL) && (*ifcNames!=NULL))
            {
                for (int i=0; ifcNames[i]!=NULL; i++)
                {
                    const char *ifcName = ifcNames[i];

                    ProvMgrIfcInfo entry;
                    entry.path = fullPath;
                    entry.ifcName = ifcName;

                    // now get the versions
                    const char ** ifcVersions = get_ver(ifcName);
                    for (int j=0; ifcVersions[j]!=NULL; j++)
                    {
                        entry.ifcVersions.append(String(ifcVersions[j]));
                        PEG_TRACE((TRC_PROVIDERMANAGER, Tracer::LEVEL3,
                            "Adding Provider type %s version %s "
                            "handled by ProviderManager %s",
                             ifcName,ifcVersions[j],
                             (const char*)fullPath.getCString()));
                    }
                    _pmArray.append(entry);
                }
            }
        }
    }
    _bInitialized = true;
}
Пример #29
0
void CIMClientRep::_connect()
{
    //
    // Test for Display optons of the form
    // Use Env variable PEGASUS_CLIENT_TRACE= <intrace> : <outtrace
    // intrace = "con" | "log" | "both"
    // outtrace = intrace
    // ex set PEGASUS_CLIENT_TRACE=BOTH:BOTH traces input and output
    // to console and log
    // Keywords are case insensitive.
    // PEP 90
    //
    Uint32 showOutput = 0;
    Uint32 showInput = 0;
#ifdef PEGASUS_CLIENT_TRACE_ENABLE
    String input;
    if (char * envVar = getenv("PEGASUS_CLIENT_TRACE"))
    {
        input = envVar;
        input.toLower();
        String io = String::EMPTY;
        Uint32 pos = input.find(':');
        if (pos == PEG_NOT_FOUND)
            pos = 0;
        else
            io = input.subString(0,pos);

        // some compilers do not allow temporaries to be passed to a
        // reference argument - so break into 2 lines
        String out = input.subString(pos + 1);
        showOutput = _getShowType(out);

        showInput = _getShowType(io);
    }
#endif

    //
    // Create response decoder:
    //
    AutoPtr<CIMOperationResponseDecoder> responseDecoder(new
            CIMOperationResponseDecoder(this, _requestEncoder.get(), &_authenticator
                                        , showInput));

    //
    // Attempt to establish a connection:
    //
    AutoPtr<HTTPConnection> httpConnection(_httpConnector->connect(
            _connectHost,
            _connectPortNumber,
            _connectSSLContext.get(),
            responseDecoder.get()));

    //
    // Create request encoder:
    //
    String connectHost = _connectHost;
    if (connectHost.size())
    {
        char portStr[32];
        sprintf(portStr, ":%u", _connectPortNumber);
        connectHost.append(portStr);
    }

    AutoPtr<CIMOperationRequestEncoder> requestEncoder(new CIMOperationRequestEncoder(
                httpConnection.get(), connectHost, &_authenticator, showOutput));

    _responseDecoder.reset(responseDecoder.release());
    _httpConnection = httpConnection.release();
    _requestEncoder.reset(requestEncoder.release());
    _responseDecoder->setEncoderQueue(_requestEncoder.get());
    _connected = true;
}
  void ResidueModification::setSourceClassification(const String & classification)
  {
    String c = classification;
    c.toLower();
    if (c == "artifact" || c == "artefact") // unimod uses Artefact (BE) not Artifact (AE)
    {
      classification_ = ARTIFACT;
      return;
    }
    if (c == "natural")
    {
      classification_ = NATURAL;
      return;
    }
    if (c == "hypothetical")
    {
      classification_ = HYPOTHETICAL;
      return;
    }
    if (c == "post-translational")
    {
      classification_ = POSTTRANSLATIONAL;
      return;
    }
    if (c == "multiple")
    {
      classification_ = MULTIPLE;
      return;
    }
    if (c == "chemical derivative")
    {
      classification_ = CHEMICAL_DERIVATIVE;
      return;
    }
    if (c == "isotopic label")
    {
      classification_ = ISOTOPIC_LABEL;
      return;
    }
    if (c == "pre-translational")
    {
      classification_ = PRETRANSLATIONAL;
      return;
    }
    if (c == "other glycosylation")
    {
      classification_ = OTHER_GLYCOSYLATION;
      return;
    }
    if (c == "n-linked glycosylation")
    {
      classification_ = NLINKED_GLYCOSYLATION;
      return;
    }
    if (c == "aa substitution")
    {
      classification_ = AA_SUBSTITUTION;
      return;
    }
    if (c == "other")
    {
      classification_ = OTHER;
      return;
    }
    if (c == "non-standard residue")
    {
      classification_ = NONSTANDARD_RESIDUE;
      return;
    }
    if (c == "co-translational")
    {
      classification_ = COTRANSLATIONAL;
      return;
    }
    if (c == "o-linked glycosylation")
    {
      classification_ = OLINKED_GLYCOSYLATION;
      return;
    }

    classification_ = UNKNOWN;

    //cerr << "ResidueModification: Unknown source classification '" << classification << "'" << endl;
    return;
  }