ProteoWizard
String.hpp
Go to the documentation of this file.
1//
2// $Id$
3//
4//
5// Original author: Matt Chambers <matt.chambers .@. vanderbilt.edu>
6//
7// Copyright 2008 Spielberg Family Center for Applied Proteomics
8// Cedars Sinai Medical Center, Los Angeles, California 90048
9// Copyright 2008 Vanderbilt University - Nashville, TN 37232
10//
11// Licensed under the Apache License, Version 2.0 (the "License");
12// you may not use this file except in compliance with the License.
13// You may obtain a copy of the License at
14//
15// http://www.apache.org/licenses/LICENSE-2.0
16//
17// Unless required by applicable law or agreed to in writing, software
18// distributed under the License is distributed on an "AS IS" BASIS,
19// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20// See the License for the specific language governing permissions and
21// limitations under the License.
22//
23
24#ifndef _STRING_HPP_
25#define _STRING_HPP_
26
27#include <string>
28#include <sstream>
29#include <boost/algorithm/string.hpp>
30#include <boost/format.hpp>
32
33using std::string;
34using std::getline;
35using std::stringstream;
36using std::istringstream;
37using std::ostringstream;
38
39#ifndef BOOST_NO_STD_WSTRING
40// these cause trouble on mingw gcc - libstdc++ widechar not fully there yet
41using std::wstring;
42using std::wstringstream;
43using std::wistringstream;
44using std::wostringstream;
45#endif
46
47namespace bal = boost::algorithm;
49using boost::bad_lexical_cast;
50using boost::format;
51
52
53namespace pwiz {
54namespace util {
55
56
57template <typename SequenceT>
58std::string longestCommonPrefix(const SequenceT& strings)
59{
60 if (strings.empty())
61 return "";
62
63 typename SequenceT::const_iterator itr = strings.begin();
64 std::string result = *itr;
65 for (++itr; itr != strings.end(); ++itr)
66 {
67 const std::string& target = *itr;
68
69 if (result.empty())
70 return "";
71
72 for (size_t j=0; j < target.length() && j < result.length(); ++j)
73 if (target[j] != result[j])
74 {
75 result.resize(j);
76 break;
77 }
78 }
79 return result;
80}
81
82
83} // namespace util
84} // namespace pwiz
85
86
87#endif // _STRING_HPP_
toType lexical_cast(const std::string &str, bool &success)
std::string longestCommonPrefix(const SequenceT &strings)
Definition String.hpp:58