X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=xmltooling%2Fexceptions.cpp;h=6ff78ca3f2aed7033d273436d541ecc0bf3eda5f;hb=990b41af1cefa4f68b2350b94330d8eafc6a56ee;hp=8f39ddc6e01c78e2cc0492f86a419a1cb68c9b26;hpb=a0d768778a8f5f539b909baf5b115e70ea765f0f;p=shibboleth%2Fcpp-xmltooling.git diff --git a/xmltooling/exceptions.cpp b/xmltooling/exceptions.cpp index 8f39ddc..6ff78ca 100644 --- a/xmltooling/exceptions.cpp +++ b/xmltooling/exceptions.cpp @@ -1,17 +1,21 @@ -/* - * Copyright 2001-2010 Internet2 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at +/** + * Licensed to the University Corporation for Advanced Internet + * Development, Inc. (UCAID) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for + * additional information regarding copyright ownership. + * + * UCAID licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the + * License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the License. */ /** @@ -30,10 +34,12 @@ #include #include #include +#include #include using namespace xmltooling; using namespace xercesc; +using namespace boost; using namespace std; using xmlconstants::XMLTOOLING_NS; @@ -101,88 +107,45 @@ void XMLToolingException::setMessage(const char* msg) m_processedmsg.erase(); } -inline const char* get_digit_character() -{ - static const char s_characters[19] = - { - '9' - , '8' - , '7' - , '6' - , '5' - , '4' - , '3' - , '2' - , '1' - , '0' - , '1' - , '2' - , '3' - , '4' - , '5' - , '6' - , '7' - , '8' - , '9' - }; - static const char *s_mid = s_characters + 9; - - return s_mid; -} - -inline const char* unsigned_integer_to_string(char* buf, size_t cchBuf, size_t i) -{ - char* psz=buf + cchBuf - 1; // Set psz to last char - *psz = 0; // Set terminating null - - do { - size_t lsd = i % 10; // Get least significant - // digit - - i /= 10; // Prepare for next most - // significant digit - - --psz; // Move back - - *psz = get_digit_character()[lsd]; // Place the digit - - } while(i!=0 && psz>buf); - - return psz; -} - void XMLToolingException::addProperties(const params& p) { m_processedmsg.erase(); - map::size_type i=m_params.size()+1; - char buf[20]; + map::size_type i = m_params.size() + 1; const vector& v=p.get(); - for (vector::const_iterator ci=v.begin(); ci!=v.end(); ci++) { - m_params[unsigned_integer_to_string(buf,sizeof(buf),i++)] = *ci; + for (vector::const_iterator ci = v.begin(); ci != v.end(); ++ci) { + try { + m_params[lexical_cast(i++)] = *ci; + } + catch (bad_lexical_cast&) { + } } } void XMLToolingException::addProperties(const namedparams& p) { m_processedmsg.erase(); - const vector& v=p.get(); - for (vector::const_iterator ci=v.begin(); ci!=v.end(); ci++) { + const vector& v = p.get(); + for (vector::const_iterator ci = v.begin(); ci != v.end(); ++ci) { m_params.erase(*ci); m_params[*ci] = *(ci+1); - ci++; // advance past name to value, then loop will advance it again + ++ci; // advance past name to value, then loop will advance it again } } const char* XMLToolingException::getProperty(unsigned int index) const { - char buf[20]; - map::const_iterator i=m_params.find(unsigned_integer_to_string(buf,sizeof(buf),index)); - return (i==m_params.end()) ? nullptr : i->second.c_str(); + try { + map::const_iterator i = m_params.find(lexical_cast(index)); + return (i==m_params.end()) ? nullptr : i->second.c_str(); + } + catch (bad_lexical_cast&) { + return nullptr; + } } const char* XMLToolingException::getProperty(const char* name) const { - map::const_iterator i=m_params.find(name); + map::const_iterator i = m_params.find(name); return (i==m_params.end()) ? nullptr : i->second.c_str(); } @@ -250,7 +213,7 @@ string XMLToolingException::toString() const if (msg) xml_encode(xml, "", msg, ""); const URLEncoder* encoder = XMLToolingConfig::getConfig().getURLEncoder(); - for (map::const_iterator i=m_params.begin(); i!=m_params.end(); i++) { + for (map::const_iterator i = m_params.begin(); i != m_params.end(); ++i) { xml_encode(xml, "", encoder->encode(i->second.c_str()).c_str(), ""); } @@ -262,7 +225,7 @@ string XMLToolingException::toQueryString() const { string q; const URLEncoder* enc = XMLToolingConfig::getConfig().getURLEncoder(); - for (map::const_iterator i=m_params.begin(); i!=m_params.end(); i++) { + for (map::const_iterator i = m_params.begin(); i != m_params.end(); ++i) { if (!q.empty()) q += '&'; q = q + i->first + '=' + enc->encode(i->second.c_str());