<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>xunwap &#187; Boost</title>
	<atom:link href="http://xunwap.net/archives/category/server-development/boost/feed" rel="self" type="application/rss+xml" />
	<link>http://xunwap.net</link>
	<description>专注移动互联网服务</description>
	<lastBuildDate>Sat, 15 Jan 2011 14:39:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>C++ String Library</title>
		<link>http://xunwap.net/archives/server-development/boost/c-string-library.html</link>
		<comments>http://xunwap.net/archives/server-development/boost/c-string-library.html#comments</comments>
		<pubDate>Sun, 09 Jan 2011 14:19:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Boost]]></category>

		<guid isPermaLink="false">http://xunwap.net/?p=763</guid>
		<description><![CDATA[用std::string来代替char*作为字符串处理的方式在现代的C++开发中已是约定俗成的规则了。不过std::string的公有成员函数的功能是很有限的，而且操作起来并不是很方便，借助于 std::algorithms 来操作std::string时，因为std::algorithms需要面对的是容器的通用操作，也以，也有部分我们所需要的std::string操作无法通过std::algorithms来实现。好在 String Algorithms Library 为std::string弥补了众多在操作上的不足之处。先看看 String Algorithms Library 的函数: Algorithms Table 21.1. Case Conversion Algorithm name Description Functions to_upper Convert a string to upper case to_upper_copy() to_upper() to_lower Convert a string to lower case to_lower_copy() to_lower() Table 21.2. Trimming Algorithm name Description Functions trim_left Remove leading spaces from a string trim_left_copy_if() trim_left_if() trim_left_copy() trim_left() trim_right Remove trailing [...]]]></description>
			<content:encoded><![CDATA[<p>用std::string来代替char*作为字符串处理的方式在现代的C++开发中已是约定俗成的规则了。不过std::string的公有成员函数的功能是很有限的，而且操作起来并不是很方便，借助于 std::algorithms 来操作std::string时，因为std::algorithms需要面对的是容器的通用操作，也以，也有部分我们所需要的std::string操作无法通过std::algorithms来实现。好在 String Algorithms Library 为std::string弥补了众多在操作上的不足之处。先看看 String Algorithms Library 的函数:</p>
<div>
<div>
<div>
<h3>Algorithms</h3>
</div>
</div>
</div>
<div>
<p><a name="id2571311"></a><strong>Table 21.1. Case Conversion</strong></p>
<div>
<table summary="Case Conversion">
<colgroup>
<col></col>
<col></col>
<col></col>
</colgroup>
<thead>
<tr>
<th align="left">Algorithm name</th>
<th align="left">Description</th>
<th align="left">Functions</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left"><code>to_upper</code></td>
<td align="left">Convert a string to upper case</td>
<td align="left"><code><a title="Function to_upper_copy" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/to_upper_copy.html">to_upper_copy()</a></code><br />
<code><a title="Function template to_upper" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/to_upper.html">to_upper()</a></code></td>
</tr>
<tr>
<td align="left"><code>to_lower</code></td>
<td align="left">Convert a string to lower case</td>
<td align="left"><code><a title="Function to_lower_copy" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/to_lower_copy.html">to_lower_copy()</a></code><br />
<code><a title="Function template to_lower" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/to_lower.html">to_lower()</a></code></td>
</tr>
</tbody>
</table>
</div>
</div>
<div>
<p><a name="id2571427"></a><strong>Table 21.2. Trimming</strong></p>
<div>
<table summary="Trimming">
<colgroup>
<col></col>
<col></col>
<col></col>
</colgroup>
<thead>
<tr>
<th align="left">Algorithm name</th>
<th align="left">Description</th>
<th align="left">Functions</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left"><code>trim_left</code></td>
<td align="left">Remove leading spaces from a string</td>
<td align="left"><code><a title="Function trim_left_copy_if" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/trim_left_copy_if.html">trim_left_copy_if()</a></code><br />
<code><a title="Function template trim_left_if" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/trim_left_if.html">trim_left_if()</a></code><br />
<code><a title="Function template trim_left_copy" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/trim_left_copy.html">trim_left_copy()</a></code><br />
<code><a title="Function template trim_left" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/trim_left.html">trim_left()</a></code></td>
</tr>
<tr>
<td align="left"><code>trim_right</code></td>
<td align="left">Remove trailing spaces from a string</td>
<td align="left"><code><a title="Function trim_right_copy_if" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/trim_right_copy_if.html">trim_right_copy_if()</a></code><br />
<code><a title="Function template trim_right_if" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/trim_right_if.html">trim_right_if()</a></code><br />
<code><a title="Function template trim_right_copy" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/trim_right_copy.html">trim_right_copy()</a></code><br />
<code><a title="Function template trim_right" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/trim_right.html">trim_right()</a></code></td>
</tr>
<tr>
<td align="left"><code>trim</code></td>
<td align="left">Remove leading and trailing spaces from a string</td>
<td align="left"><code><a title="Function trim_copy_if" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/trim_copy_if.html">trim_copy_if()</a></code><br />
<code><a title="Function template trim_if" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/trim_if.html">trim_if()</a></code><br />
<code><a title="Function template trim_copy" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/trim_copy.html">trim_copy()</a></code><br />
<code><a title="Function template trim" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/trim.html">trim()</a></code></td>
</tr>
</tbody>
</table>
</div>
</div>
<div>
<p><a name="id2571675"></a><strong>Table 21.3. Predicates</strong></p>
<div>
<table summary="Predicates">
<colgroup>
<col></col>
<col></col>
<col></col>
</colgroup>
<thead>
<tr>
<th align="left">Algorithm name</th>
<th align="left">Description</th>
<th align="left">Functions</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left"><code>starts_with</code></td>
<td align="left">Check if a string is a prefix of the other one</td>
<td align="left"><code><a title="Function starts_with" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/starts_with.html">starts_with()</a></code><br />
<code><a title="Function template istarts_with" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/istarts_with.html">istarts_with()</a></code></td>
</tr>
<tr>
<td align="left"><code>ends_with</code></td>
<td align="left">Check if a string is a suffix of the other one</td>
<td align="left"><code><a title="Function ends_with" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/ends_with.html">ends_with()</a></code><br />
<code><a title="Function template iends_with" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/iends_with.html">iends_with()</a></code></td>
</tr>
<tr>
<td align="left"><code>contains</code></td>
<td align="left">Check if a string is contained of the other one</td>
<td align="left"><code><a title="Function contains" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/contains.html">contains()</a></code><br />
<code><a title="Function template icontains" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/icontains.html">icontains()</a></code></td>
</tr>
<tr>
<td align="left"><code>equals</code></td>
<td align="left">Check if two strings are equal</td>
<td align="left"><code><a title="Function equals" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/equals.html">equals()</a></code><br />
<code><a title="Function template iequals" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/iequals.html">iequals()</a></code></td>
</tr>
<tr>
<td align="left"><code>lexicographical_compare</code></td>
<td align="left">Check if a string is lexicographically less then another one</td>
<td align="left"><code><a title="Function lexicographical_compare" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/lexicographical_compare.html">lexicographical_compare()</a></code><br />
<code><a title="Function template ilexicographical_compare" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/ilexicographical_compare.html">ilexicographical_compare()</a></code></td>
</tr>
<tr>
<td align="left"><code>all</code></td>
<td align="left">Check if all elements of a string satisfy the given predicate</td>
<td align="left"><code><a title="Function template all" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/all.html">all()</a></code></td>
</tr>
</tbody>
</table>
</div>
</div>
<div>
<p><a name="id2571950"></a><strong>Table 21.4. Find algorithms</strong></p>
<div>
<table summary="Find algorithms">
<colgroup>
<col></col>
<col></col>
<col></col>
</colgroup>
<thead>
<tr>
<th align="left">Algorithm name</th>
<th align="left">Description</th>
<th align="left">Functions</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">find_first</td>
<td align="left">Find the first occurrence of a string in the input</td>
<td align="left"><code><a title="Function template find_first" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/find_first.html">find_first()</a></code><br />
<code><a title="Function template ifind_first" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/ifind_first.html">ifind_first()</a></code></td>
</tr>
<tr>
<td align="left">find_last</td>
<td align="left">Find the last occurrence of a string in the input</td>
<td align="left"><code><a title="Function template find_last" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/find_last.html">find_last()</a></code><br />
<code><a title="Function template ifind_last" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/ifind_last.html">ifind_last()</a></code></td>
</tr>
<tr>
<td align="left">find_nth</td>
<td align="left">Find the nth (zero-indexed) occurrence of a string in the input</td>
<td align="left"><code><a title="Function template find_nth" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/find_nth.html">find_nth()</a></code><br />
<code><a title="Function template ifind_nth" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/ifind_nth.html">ifind_nth()</a></code></td>
</tr>
<tr>
<td align="left">find_head</td>
<td align="left">Retrieve the head of a string</td>
<td align="left"><code><a title="Function template find_head" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/find_head.html">find_head()</a></code></td>
</tr>
<tr>
<td align="left">find_tail</td>
<td align="left">Retrieve the tail of a string</td>
<td align="left"><code><a title="Function template find_tail" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/find_tail.html">find_tail()</a></code></td>
</tr>
<tr>
<td align="left">find_token</td>
<td align="left">Find first matching token in the string</td>
<td align="left"><code><a title="Function template find_token" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/find_token.html">find_token()</a></code></td>
</tr>
<tr>
<td align="left">find_regex</td>
<td align="left">Use the regular expression to search the string</td>
<td align="left"><code><a title="Function template find_regex" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/find_regex.html">find_regex()</a></code></td>
</tr>
<tr>
<td align="left">find</td>
<td align="left">Generic find algorithm</td>
<td align="left"><code><a title="Function template find" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/find.html">find()</a></code></td>
</tr>
</tbody>
</table>
</div>
</div>
<div>
<p><a name="id2572226"></a><strong>Table 21.5. Erase/Replace</strong></p>
<div>
<table summary="Erase/Replace">
<colgroup>
<col></col>
<col></col>
<col></col>
</colgroup>
<thead>
<tr>
<th align="left">Algorithm name</th>
<th align="left">Description</th>
<th align="left">Functions</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">replace/erase_first</td>
<td align="left">Replace/Erase the first occurrence of a string in the input</td>
<td align="left"><code><a title="Function template replace_first" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/replace_first.html">replace_first()</a></code><br />
<code><a title="Function replace_first_copy" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/replace_first_copy.html">replace_first_copy()</a></code><br />
<code><a title="Function template ireplace_first" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/ireplace_first.html">ireplace_first()</a></code><br />
<code><a title="Function ireplace_first_copy" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/ireplace_first_copy.html">ireplace_first_copy()</a></code><br />
<code><a title="Function template erase_first" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/erase_first.html">erase_first()</a></code><br />
<code><a title="Function erase_first_copy" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/erase_first_copy.html">erase_first_copy()</a></code><br />
<code><a title="Function template ierase_first" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/ierase_first.html">ierase_first()</a></code><br />
<code><a title="Function ierase_first_copy" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/ierase_first_copy.html">ierase_first_copy()</a></code></td>
</tr>
<tr>
<td align="left">replace/erase_last</td>
<td align="left">Replace/Erase the last occurrence of a string in the input</td>
<td align="left"><code><a title="Function template replace_last" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/replace_last.html">replace_last()</a></code><br />
<code><a title="Function replace_last_copy" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/replace_last_copy.html">replace_last_copy()</a></code><br />
<code><a title="Function template ireplace_last" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/ireplace_last.html">ireplace_last()</a></code><br />
<code><a title="Function ireplace_last_copy" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/ireplace_last_copy.html">ireplace_last_copy()</a></code><br />
<code><a title="Function template erase_last" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/erase_last.html">erase_last()</a></code><br />
<code><a title="Function erase_last_copy" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/erase_last_copy.html">erase_last_copy()</a></code><br />
<code><a title="Function template ierase_last" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/ierase_last.html">ierase_last()</a></code><br />
<code><a title="Function ierase_last_copy" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/ierase_last_copy.html">ierase_last_copy()</a></code></td>
</tr>
<tr>
<td align="left">replace/erase_nth</td>
<td align="left">Replace/Erase the nth (zero-indexed) occurrence of a string in the input</td>
<td align="left"><code><a title="Function template replace_nth" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/replace_nth.html">replace_nth()</a></code><br />
<code><a title="Function replace_nth_copy" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/replace_nth_copy.html">replace_nth_copy()</a></code><br />
<code><a title="Function template ireplace_nth" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/ireplace_nth.html">ireplace_nth()</a></code><br />
<code><a title="Function ireplace_nth_copy" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/ireplace_nth_copy.html">ireplace_nth_copy()</a></code><br />
<code><a title="Function template erase_nth" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/erase_nth.html">erase_nth()</a></code><br />
<code><a title="Function erase_nth_copy" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/erase_nth_copy.html">erase_nth_copy()</a></code><br />
<code><a title="Function template ierase_nth" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/ierase_nth.html">ierase_nth()</a></code><br />
<code><a title="Function ierase_nth_copy" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/ierase_nth_copy.html">ierase_nth_copy()</a></code></td>
</tr>
<tr>
<td align="left">replace/erase_all</td>
<td align="left">Replace/Erase the all occurrences of a string in the input</td>
<td align="left"><code><a title="Function template replace_all" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/replace_all.html">replace_all()</a></code><br />
<code><a title="Function replace_all_copy" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/replace_all_copy.html">replace_all_copy()</a></code><br />
<code><a title="Function template ireplace_all" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/ireplace_all.html">ireplace_all()</a></code><br />
<code><a title="Function ireplace_all_copy" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/ireplace_all_copy.html">ireplace_all_copy()</a></code><br />
<code><a title="Function template erase_all" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/erase_all.html">erase_all()</a></code><br />
<code><a title="Function erase_all_copy" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/erase_all_copy.html">erase_all_copy()</a></code><br />
<code><a title="Function template ierase_all" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/ierase_all.html">ierase_all()</a></code><br />
<code><a title="Function ierase_all_copy" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/ierase_all_copy.html">ierase_all_copy()</a></code></td>
</tr>
<tr>
<td align="left">replace/erase_head</td>
<td align="left">Replace/Erase the head of the input</td>
<td align="left"><code><a title="Function template replace_head" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/replace_head.html">replace_head()</a></code><br />
<code><a title="Function replace_head_copy" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/replace_head_copy.html">replace_head_copy()</a></code><br />
<code><a title="Function template erase_head" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/erase_head.html">erase_head()</a></code><br />
<code><a title="Function erase_head_copy" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/erase_head_copy.html">erase_head_copy()</a></code></td>
</tr>
<tr>
<td align="left">replace/erase_tail</td>
<td align="left">Replace/Erase the tail of the input</td>
<td align="left"><code><a title="Function template replace_tail" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/replace_tail.html">replace_tail()</a></code><br />
<code><a title="Function replace_tail_copy" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/replace_tail_copy.html">replace_tail_copy()</a></code><br />
<code><a title="Function template erase_tail" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/erase_tail.html">erase_tail()</a></code><br />
<code><a title="Function erase_tail_copy" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/erase_tail_copy.html">erase_tail_copy()</a></code></td>
</tr>
<tr>
<td align="left">replace/erase_regex</td>
<td align="left">Replace/Erase a substring matching the given regular expression</td>
<td align="left"><code><a title="Function template replace_regex" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/replace_regex.html">replace_regex()</a></code><br />
<code><a title="Function replace_regex_copy" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/replace_regex_copy.html">replace_regex_copy()</a></code><br />
<code><a title="Function template erase_regex" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/erase_regex.html">erase_regex()</a></code><br />
<code><a title="Function erase_regex_copy" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/erase_regex_copy.html">erase_regex_copy()</a></code></td>
</tr>
<tr>
<td align="left">replace/erase_regex_all</td>
<td align="left">Replace/Erase all substrings matching the given regular expression</td>
<td align="left"><code><a title="Function template replace_all_regex" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/replace_all_regex.html">replace_all_regex()</a></code><br />
<code><a title="Function replace_all_regex_copy" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/replace_all_regex_copy.html">replace_all_regex_copy()</a></code><br />
<code><a title="Function template erase_all_regex" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/erase_all_regex.html">erase_all_regex()</a></code><br />
<code><a title="Function erase_all_regex_copy" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/erase_all_regex_copy.html">erase_all_regex_copy()</a></code></td>
</tr>
<tr>
<td align="left">find_format</td>
<td align="left">Generic replace algorithm</td>
<td align="left"><code><a title="Function template find_format" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/find_format.html">find_format()</a></code><br />
<code><a title="Function find_format_copy" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/find_format_copy.html">find_format_copy()</a></code><br />
<code><a title="Function template find_format_all" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/find_format_all.html">find_format_all()</a></code><br />
<code><a title="Function find_format_all_copy" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/find_format_all_copy.html">find_format_all_copy()()</a></code></td>
</tr>
</tbody>
</table>
</div>
</div>
<div>
<p><a name="id2573116"></a><strong>Table 21.6. Split</strong></p>
<div>
<table summary="Split">
<colgroup>
<col></col>
<col></col>
<col></col>
</colgroup>
<thead>
<tr>
<th align="left">Algorithm name</th>
<th align="left">Description</th>
<th align="left">Functions</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">find_all</td>
<td align="left">Find/Extract all matching substrings in the input</td>
<td align="left"><code><a title="Function template find_all" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/find_all.html">find_all()</a></code><br />
<code><a title="Function template ifind_all" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/ifind_all.html">ifind_all()</a></code><br />
<code><a title="Function template find_all_regex" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/find_all_regex.html">find_all_regex()</a></code></td>
</tr>
<tr>
<td align="left">split</td>
<td align="left">Split input into parts</td>
<td align="left"><code><a title="Function template split" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/split_id640478.html">split()</a></code><br />
<code><a title="Function template split_regex" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/split_regex.html">split_regex()</a></code></td>
</tr>
<tr>
<td align="left">iter_find</td>
<td align="left">Iteratively apply the finder to the input to find all matching substrings</td>
<td align="left"><code><a title="Function template iter_find" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/iter_find.html">iter_find()</a></code></td>
</tr>
<tr>
<td align="left">iter_split</td>
<td align="left">Use the finder to find matching substrings in the input and use them as separators to split the input into parts</td>
<td align="left"><code><a title="Function template iter_split" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/iter_split.html">iter_split()</a></code></td>
</tr>
</tbody>
</table>
</div>
</div>
<div>
<p><a name="id2573293"></a><strong>Table 21.7. Join</strong></p>
<div>
<table summary="Join">
<colgroup>
<col></col>
<col></col>
<col></col>
</colgroup>
<thead>
<tr>
<th align="left">Algorithm name</th>
<th align="left">Description</th>
<th align="left">Functions</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">join</td>
<td align="left">Join all elements in a container into a single string</td>
<td align="left"><code><a title="Function template join" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/join.html">join</a></code></td>
</tr>
<tr>
<td align="left">join_if</td>
<td align="left">Join all elements in a container that satisfies the condition into a single string</td>
<td align="left"><code><a title="Function template join_if" href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/algorithm/join_if_id626240.html">join_if()</a></code></td>
</tr>
</tbody>
</table>
</div>
</div>
<p>Boost.String_Algo 的函数功能是相当的丰富了，也简便易用。所以可以在开发过程中大量使用。</p>
<p>BTW:有很多的人都排斥Boost，在一开始的时候我也不使用Boost，因为有太多的人建议我不要用。后来我还是使用了Boost，而且越用越喜欢，也越发感觉到Boost是一个多么灵活，高效，强大的C++ Library;也体会到了为什么可以称Boost具有&#8221;工业强度&#8221;。在这里，我建议那些不愿意使用Boost的朋友去使用一下Boost，也许你们是听别人建议不要用Boost，也许是自己不愿意使用Boost，但你们一定要去试用Boost中的一些可能用得上的Library，也许用了之后你们的看法会有所改变，也许你们会有不同的发现 <img src='http://xunwap.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p style="padding-left: 390px;"><strong><a title="C++ 字符串操作库" href="http://xunwap.net/archives/server-development/boost/c-string-library.html" target="_blank">本站原创文章，转载请注明出处</a>。 </strong></p>
]]></content:encoded>
			<wfw:commentRss>http://xunwap.net/archives/server-development/boost/c-string-library.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>boost.property_tree使用示例</title>
		<link>http://xunwap.net/archives/server-development/boost/boost-property_tree%e4%bd%bf%e7%94%a8%e7%a4%ba%e4%be%8b.html</link>
		<comments>http://xunwap.net/archives/server-development/boost/boost-property_tree%e4%bd%bf%e7%94%a8%e7%a4%ba%e4%be%8b.html#comments</comments>
		<pubDate>Wed, 08 Dec 2010 15:32:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Boost]]></category>
		<category><![CDATA[ini]]></category>
		<category><![CDATA[property_tree]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://xunwap.net/?p=671</guid>
		<description><![CDATA[boost.property_tree使用示例]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste">下面是一个使用boost.property_tree来解析XML/INI文件的简单示例。</div>
<div id="_mcePaste">使用boost.property_tree来作为配置文件的解析工具非常合适.</div>
<pre style="color: #000000; background-color: #eeeeee; font-size: 10pt; font-family: 'Courier New';"><span style="color: #0080c0; font-weight: bold;">#include &lt;iostream&gt;</span>
<span style="color: #0080c0; font-weight: bold;">#include &lt;string&gt;</span>
<span style="color: #0080c0; font-weight: bold;">#include &lt;algorithm&gt;</span>
<span style="color: #0080c0; font-weight: bold;">#include &lt;iterator&gt;</span>
<span style="color: #0080c0; font-weight: bold;">#include &lt;set&gt;</span>

<span style="color: #0080c0; font-weight: bold;">#include &lt;stdlib.h&gt;</span>
<span style="color: #0080c0; font-weight: bold;">#include &lt;unistd.h&gt;</span>

<span style="color: #0080c0; font-weight: bold;">#include &lt;boost/foreach.hpp&gt;</span>
<span style="color: #0080c0; font-weight: bold;">#include &lt;boost/noncopyable.hpp&gt;</span>
<span style="color: #0080c0; font-weight: bold;">#include &lt;boost/property_tree/ptree.hpp&gt;</span>
<span style="color: #0080c0; font-weight: bold;">#include &lt;boost/property_tree/xml_parser.hpp&gt;</span>
<span style="color: #0080c0; font-weight: bold;">#include &lt;boost/property_tree/ini_parser.hpp&gt;</span>

<span style="color: #8080c0; font-weight: bold;">int</span> <span style="color: #004466;">main</span><span style="color: #ff0080; font-weight: bold;">(</span> <span style="color: #8080c0; font-weight: bold;">int</span> argc <span style="color: #ff0080; font-weight: bold;">,</span> <span style="color: #8080c0; font-weight: bold;">char</span> <span style="color: #ff0080; font-weight: bold;">*</span>argv<span style="color: #ff0080; font-weight: bold;">[] )</span>
<span style="color: #ff0080; font-weight: bold;">{</span>
    std<span style="color: #ff0080; font-weight: bold;">::</span>string <span style="color: #004466;">strConfigName</span><span style="color: #ff0080; font-weight: bold;">(</span> <span style="color: #a68500;">""</span> <span style="color: #ff0080; font-weight: bold;">);</span>
    std<span style="color: #ff0080; font-weight: bold;">::</span>string <span style="color: #004466;">strReportName</span><span style="color: #ff0080; font-weight: bold;">(</span> <span style="color: #a68500;">""</span> <span style="color: #ff0080; font-weight: bold;">);</span>

    <span style="color: #8080c0; font-weight: bold;">const char</span> <span style="color: #ff0080; font-weight: bold;">*</span>szShortOptions <span style="color: #ff0080; font-weight: bold;">=</span> <span style="color: #a68500;">":f:t:h"</span><span style="color: #ff0080; font-weight: bold;">;</span>
    <span style="color: #bb7977; font-weight: bold;">while</span> <span style="color: #ff0080; font-weight: bold;">(</span> <span style="color: #bb7977; font-weight: bold;">true</span> <span style="color: #ff0080; font-weight: bold;">)</span>
    <span style="color: #ff0080; font-weight: bold;">{</span>
        <span style="color: #8080c0; font-weight: bold;">const int</span> iOption <span style="color: #ff0080; font-weight: bold;">=</span> <span style="color: #004466;">getopt</span><span style="color: #ff0080; font-weight: bold;">(</span> argc <span style="color: #ff0080; font-weight: bold;">,</span> argv <span style="color: #ff0080; font-weight: bold;">,</span> szShortOptions <span style="color: #ff0080; font-weight: bold;">);</span>
        <span style="color: #bb7977; font-weight: bold;">if</span> <span style="color: #ff0080; font-weight: bold;">( -</span><span style="color: #800080; font-weight: bold;">1</span> <span style="color: #ff0080; font-weight: bold;">==</span> iOption <span style="color: #ff0080; font-weight: bold;">)</span>
        <span style="color: #ff0080; font-weight: bold;">{</span>
            <span style="color: #bb7977; font-weight: bold;">break</span><span style="color: #ff0080; font-weight: bold;">;</span>
        <span style="color: #ff0080; font-weight: bold;">}</span>

        <span style="color: #bb7977; font-weight: bold;">switch</span> <span style="color: #ff0080; font-weight: bold;">(</span> iOption <span style="color: #ff0080; font-weight: bold;">)</span>
        <span style="color: #ff0080; font-weight: bold;">{</span>
        <span style="color: #bb7977; font-weight: bold;">case</span> <span style="color: #a68500;">'f'</span><span style="color: #ff0080; font-weight: bold;">:</span>
        <span style="color: #ff0080; font-weight: bold;">{</span>
            strConfigName <span style="color: #ff0080; font-weight: bold;">=</span> optarg<span style="color: #ff0080; font-weight: bold;">;</span>
        <span style="color: #ff0080; font-weight: bold;">}</span>
        <span style="color: #bb7977; font-weight: bold;">break</span><span style="color: #ff0080; font-weight: bold;">;</span>

        <span style="color: #bb7977; font-weight: bold;">case</span> <span style="color: #a68500;">'t'</span><span style="color: #ff0080; font-weight: bold;">:</span>
        <span style="color: #ff0080; font-weight: bold;">{</span>
            strReportName <span style="color: #ff0080; font-weight: bold;">=</span> optarg<span style="color: #ff0080; font-weight: bold;">;</span>
        <span style="color: #ff0080; font-weight: bold;">}</span>
        <span style="color: #bb7977; font-weight: bold;">break</span><span style="color: #ff0080; font-weight: bold;">;</span>

        <span style="color: #bb7977; font-weight: bold;">case</span> <span style="color: #a68500;">':'</span><span style="color: #ff0080; font-weight: bold;">:</span>
        <span style="color: #ff0080; font-weight: bold;">{</span>
            std<span style="color: #ff0080; font-weight: bold;">::</span>cerr <span style="color: #ff0080; font-weight: bold;">&lt;&lt;</span> <span style="color: #a68500;">"-"</span> <span style="color: #ff0080; font-weight: bold;">&lt;&lt;</span> <span style="color: #bb7977; font-weight: bold;">static_cast</span><span style="color: #ff0080; font-weight: bold;">&lt;</span> <span style="color: #8080c0; font-weight: bold;">char</span> <span style="color: #ff0080; font-weight: bold;">&gt;(</span> iOption <span style="color: #ff0080; font-weight: bold;">)</span> \
                      <span style="color: #ff0080; font-weight: bold;">&lt;&lt;</span> <span style="color: #a68500;">" need option value."</span> <span style="color: #ff0080; font-weight: bold;">&lt;&lt;</span> std<span style="color: #ff0080; font-weight: bold;">::</span>endl<span style="color: #ff0080; font-weight: bold;">;</span>
        <span style="color: #ff0080; font-weight: bold;">}</span>
        <span style="color: #bb7977; font-weight: bold;">break</span><span style="color: #ff0080; font-weight: bold;">;</span>

        <span style="color: #bb7977; font-weight: bold;">case</span> <span style="color: #a68500;">'h'</span><span style="color: #ff0080; font-weight: bold;">:</span>
        <span style="color: #ff0080; font-weight: bold;">{</span>
            std<span style="color: #ff0080; font-weight: bold;">::</span>cout <span style="color: #ff0080; font-weight: bold;">&lt;&lt;</span> <span style="color: #a68500;">"usage: "</span> <span style="color: #ff0080; font-weight: bold;">&lt;&lt;</span> argv<span style="color: #ff0080; font-weight: bold;">[</span> <span style="color: #800080; font-weight: bold;">0</span> <span style="color: #ff0080; font-weight: bold;">] &lt;&lt;</span> <span style="color: #a68500;">" -f config [-h]"</span>
                      <span style="color: #ff0080; font-weight: bold;">&lt;&lt;</span> std<span style="color: #ff0080; font-weight: bold;">::</span>endl<span style="color: #ff0080; font-weight: bold;">;</span>
            std<span style="color: #ff0080; font-weight: bold;">::</span>cout <span style="color: #ff0080; font-weight: bold;">&lt;&lt;</span> <span style="color: #a68500;">"-f config     specify the config file name."</span> \
                      <span style="color: #ff0080; font-weight: bold;">&lt;&lt;</span> std<span style="color: #ff0080; font-weight: bold;">::</span>endl<span style="color: #ff0080; font-weight: bold;">;</span>
            std<span style="color: #ff0080; font-weight: bold;">::</span>cout <span style="color: #ff0080; font-weight: bold;">&lt;&lt;</span> <span style="color: #a68500;">"-t report     specify the target report name."</span> \
                      <span style="color: #ff0080; font-weight: bold;">&lt;&lt;</span> std<span style="color: #ff0080; font-weight: bold;">::</span>endl<span style="color: #ff0080; font-weight: bold;">;</span>
            std<span style="color: #ff0080; font-weight: bold;">::</span>cout <span style="color: #ff0080; font-weight: bold;">&lt;&lt;</span> <span style="color: #a68500;">"-h            show the help information."</span> \
                      <span style="color: #ff0080; font-weight: bold;">&lt;&lt;</span> std<span style="color: #ff0080; font-weight: bold;">::</span>endl<span style="color: #ff0080; font-weight: bold;">;</span>

        <span style="color: #ff0080; font-weight: bold;">}</span>
        <span style="color: #bb7977; font-weight: bold;">return</span> EXIT_SUCCESS<span style="color: #ff0080; font-weight: bold;">;</span>

        <span style="color: #bb7977; font-weight: bold;">case</span> <span style="color: #a68500;">'?'</span><span style="color: #ff0080; font-weight: bold;">:</span>
        <span style="color: #bb7977; font-weight: bold;">default</span><span style="color: #ff0080; font-weight: bold;">:</span>
        <span style="color: #ff0080; font-weight: bold;">{</span>
            std<span style="color: #ff0080; font-weight: bold;">::</span>cerr <span style="color: #ff0080; font-weight: bold;">&lt;&lt;</span> <span style="color: #a68500;">"unknown option: "</span> <span style="color: #ff0080; font-weight: bold;">&lt;&lt;</span> <span style="color: #bb7977; font-weight: bold;">static_cast</span><span style="color: #ff0080; font-weight: bold;">&lt;</span> <span style="color: #8080c0; font-weight: bold;">char</span> <span style="color: #ff0080; font-weight: bold;">&gt;(</span> iOption <span style="color: #ff0080; font-weight: bold;">)</span> \
                      <span style="color: #ff0080; font-weight: bold;">&lt;&lt;</span> std<span style="color: #ff0080; font-weight: bold;">::</span>endl<span style="color: #ff0080; font-weight: bold;">;</span>
        <span style="color: #ff0080; font-weight: bold;">}</span>
        <span style="color: #bb7977; font-weight: bold;">break</span><span style="color: #ff0080; font-weight: bold;">;</span>

        <span style="color: #ff0080; font-weight: bold;">}</span>
    <span style="color: #ff0080; font-weight: bold;">}</span>

    <span style="color: #bb7977; font-weight: bold;">if</span> <span style="color: #ff0080; font-weight: bold;">( (</span> <span style="color: #bb7977; font-weight: bold;">true</span> <span style="color: #ff0080; font-weight: bold;">==</span> strConfigName<span style="color: #ff0080; font-weight: bold;">.</span><span style="color: #004466;">empty</span><span style="color: #ff0080; font-weight: bold;">() )</span> \
            <span style="color: #ff0080; font-weight: bold;">|| (</span> <span style="color: #bb7977; font-weight: bold;">true</span> <span style="color: #ff0080; font-weight: bold;">==</span> strReportName<span style="color: #ff0080; font-weight: bold;">.</span><span style="color: #004466;">empty</span><span style="color: #ff0080; font-weight: bold;">() ) )</span>
    <span style="color: #ff0080; font-weight: bold;">{</span>
        std<span style="color: #ff0080; font-weight: bold;">::</span>cout <span style="color: #ff0080; font-weight: bold;">&lt;&lt;</span> <span style="color: #a68500;">"ERROR, usage: "</span> <span style="color: #ff0080; font-weight: bold;">&lt;&lt;</span> argv<span style="color: #ff0080; font-weight: bold;">[</span> <span style="color: #800080; font-weight: bold;">0</span> <span style="color: #ff0080; font-weight: bold;">]</span> \
                  <span style="color: #ff0080; font-weight: bold;">&lt;&lt;</span> <span style="color: #a68500;">" -f config"</span> \
                  <span style="color: #ff0080; font-weight: bold;">&lt;&lt;</span> <span style="color: #a68500;">"</span><span style="color: #ff00ff; font-weight: bold;">\t</span><span style="color: #a68500;">"</span> \
                  <span style="color: #ff0080; font-weight: bold;">&lt;&lt;</span> <span style="color: #a68500;">" -t report"</span>
                  <span style="color: #ff0080; font-weight: bold;">&lt;&lt;</span> std<span style="color: #ff0080; font-weight: bold;">::</span>endl<span style="color: #ff0080; font-weight: bold;">;</span>
        <span style="color: #bb7977; font-weight: bold;">return</span> <span style="color: #ff0080; font-weight: bold;">-</span><span style="color: #800080; font-weight: bold;">1</span><span style="color: #ff0080; font-weight: bold;">;</span>
    <span style="color: #ff0080; font-weight: bold;">}</span>

    <span style="color: #ff8000;">/*</span>

<span style="color: #ff8000;">        typedef ::boost::property_tree::ptree IniParser;</span>
<span style="color: #ff8000;">        IniParser iniParser;</span>

<span style="color: #ff8000;">        const std::string strNullString = "";</span>
<span style="color: #ff8000;">        const int iDefaultIntValue = 0;</span>

<span style="color: #ff8000;">        read_ini( strConfigName , iniParser );</span>
<span style="color: #ff8000;">        const std::string strLogName = iniParser.get( "debug.log_name" , strNullString );</span>
<span style="color: #ff8000;">        const int iLogLevel = iniParser.get( "debug.level" , iDefaultIntValue );</span>

<span style="color: #ff8000;">        typedef std::set&lt; std::string &gt; ModuleSet;</span>
<span style="color: #ff8000;">        ModuleSet moduleSet;</span>

<span style="color: #ff8000;">        BOOST_FOREACH( IniParser::value_type &amp;node , \</span>
<span style="color: #ff8000;">                iniParser.get_child( "modules" ) )</span>
<span style="color: #ff8000;">        {</span>
<span style="color: #ff8000;">                moduleSet.insert( node.second.data() );</span>
<span style="color: #ff8000;">        }</span>

<span style="color: #ff8000;">        std::string strIndex( "1" );</span>

<span style="color: #ff8000;">        IniParser reportINI;</span>
<span style="color: #ff8000;">        reportINI.put( "debug.log_name" , strLogName );</span>
<span style="color: #ff8000;">        reportINI.put( "debug.level" , iLogLevel);</span>
<span style="color: #ff8000;">        BOOST_FOREACH( const std::string &amp;strName , moduleSet )</span>
<span style="color: #ff8000;">        {</span>
<span style="color: #ff8000;">                reportINI.put( "modules.module" + strIndex , \</span>
<span style="color: #ff8000;">                        strName );</span>
<span style="color: #ff8000;">                strIndex[ 0 ] += 1;</span>
<span style="color: #ff8000;">        }</span>

<span style="color: #ff8000;">        write_ini( strReportName , reportINI );</span>
<span style="color: #ff8000;">    */</span>

    <span style="color: #0080c0;">typedef</span> <span style="color: #ff0080; font-weight: bold;">::</span>boost<span style="color: #ff0080; font-weight: bold;">::</span>property_tree<span style="color: #ff0080; font-weight: bold;">::</span>ptree XmlParser<span style="color: #ff0080; font-weight: bold;">;</span>
    XmlParser xmlParser<span style="color: #ff0080; font-weight: bold;">;</span>

    <span style="color: #8080c0; font-weight: bold;">const</span> std<span style="color: #ff0080; font-weight: bold;">::</span>string strNullString <span style="color: #ff0080; font-weight: bold;">=</span> <span style="color: #a68500;">""</span><span style="color: #ff0080; font-weight: bold;">;</span>
    <span style="color: #8080c0; font-weight: bold;">const int</span> iDefaultIntValue <span style="color: #ff0080; font-weight: bold;">=</span> <span style="color: #800080; font-weight: bold;">0</span><span style="color: #ff0080; font-weight: bold;">;</span>

    <span style="color: #004466;">read_xml</span><span style="color: #ff0080; font-weight: bold;">(</span> strConfigName <span style="color: #ff0080; font-weight: bold;">,</span> xmlParser <span style="color: #ff0080; font-weight: bold;">);</span>
    <span style="color: #8080c0; font-weight: bold;">const</span> std<span style="color: #ff0080; font-weight: bold;">::</span>string strLogName <span style="color: #ff0080; font-weight: bold;">=</span> xmlParser<span style="color: #ff0080; font-weight: bold;">.</span><span style="color: #004466;">get</span><span style="color: #ff0080; font-weight: bold;">(</span> <span style="color: #a68500;">"debug.log_name"</span> <span style="color: #ff0080; font-weight: bold;">,</span> strNullString <span style="color: #ff0080; font-weight: bold;">);</span>
    <span style="color: #8080c0; font-weight: bold;">const int</span> iLogLevel <span style="color: #ff0080; font-weight: bold;">=</span> xmlParser<span style="color: #ff0080; font-weight: bold;">.</span><span style="color: #004466;">get</span><span style="color: #ff0080; font-weight: bold;">(</span> <span style="color: #a68500;">"debug.level"</span> <span style="color: #ff0080; font-weight: bold;">,</span> iDefaultIntValue <span style="color: #ff0080; font-weight: bold;">);</span>

    <span style="color: #0080c0;">typedef</span> std<span style="color: #ff0080; font-weight: bold;">::</span>set<span style="color: #ff0080; font-weight: bold;">&lt;</span> std<span style="color: #ff0080; font-weight: bold;">::</span>string <span style="color: #ff0080; font-weight: bold;">&gt;</span> ModuleSet<span style="color: #ff0080; font-weight: bold;">;</span>
    ModuleSet moduleSet<span style="color: #ff0080; font-weight: bold;">;</span>

    <span style="color: #004466;">BOOST_FOREACH</span><span style="color: #ff0080; font-weight: bold;">(</span> XmlParser<span style="color: #ff0080; font-weight: bold;">::</span>value_type <span style="color: #ff0080; font-weight: bold;">&amp;</span>node <span style="color: #ff0080; font-weight: bold;">,</span> \
                   xmlParser<span style="color: #ff0080; font-weight: bold;">.</span><span style="color: #004466;">get_child</span><span style="color: #ff0080; font-weight: bold;">(</span> <span style="color: #a68500;">"debug.modules"</span> <span style="color: #ff0080; font-weight: bold;">) )</span>
    <span style="color: #ff0080; font-weight: bold;">{</span>
        moduleSet<span style="color: #ff0080; font-weight: bold;">.</span><span style="color: #004466;">insert</span><span style="color: #ff0080; font-weight: bold;">(</span> node<span style="color: #ff0080; font-weight: bold;">.</span>second<span style="color: #ff0080; font-weight: bold;">.</span><span style="color: #004466;">data</span><span style="color: #ff0080; font-weight: bold;">() );</span>
    <span style="color: #ff0080; font-weight: bold;">}</span>

    XmlParser reportXml<span style="color: #ff0080; font-weight: bold;">;</span>
    reportXml<span style="color: #ff0080; font-weight: bold;">.</span><span style="color: #004466;">put</span><span style="color: #ff0080; font-weight: bold;">(</span> <span style="color: #a68500;">"debug.log_name"</span> <span style="color: #ff0080; font-weight: bold;">,</span> strLogName <span style="color: #ff0080; font-weight: bold;">);</span>
    reportXml<span style="color: #ff0080; font-weight: bold;">.</span><span style="color: #004466;">put</span><span style="color: #ff0080; font-weight: bold;">(</span> <span style="color: #a68500;">"debug.level"</span> <span style="color: #ff0080; font-weight: bold;">,</span> iLogLevel<span style="color: #ff0080; font-weight: bold;">);</span>
    <span style="color: #004466;">BOOST_FOREACH</span><span style="color: #ff0080; font-weight: bold;">(</span> <span style="color: #8080c0; font-weight: bold;">const</span> std<span style="color: #ff0080; font-weight: bold;">::</span>string <span style="color: #ff0080; font-weight: bold;">&amp;</span>strName <span style="color: #ff0080; font-weight: bold;">,</span> moduleSet <span style="color: #ff0080; font-weight: bold;">)</span>
    <span style="color: #ff0080; font-weight: bold;">{</span>
        reportXml<span style="color: #ff0080; font-weight: bold;">.</span><span style="color: #004466;">put</span><span style="color: #ff0080; font-weight: bold;">(</span> <span style="color: #a68500;">"debug.modules.module"</span> <span style="color: #ff0080; font-weight: bold;">,</span> \
                       strName <span style="color: #ff0080; font-weight: bold;">);</span>
    <span style="color: #ff0080; font-weight: bold;">}</span>

    <span style="color: #004466;">write_xml</span><span style="color: #ff0080; font-weight: bold;">(</span> strReportName <span style="color: #ff0080; font-weight: bold;">,</span> reportXml <span style="color: #ff0080; font-weight: bold;">);</span>

    <span style="color: #bb7977; font-weight: bold;">return</span> EXIT_SUCCESS<span style="color: #ff0080; font-weight: bold;">;</span>

<span style="color: #ff0080; font-weight: bold;">}</span></pre>
<p style="padding-left: 390px;"><strong>本站原创文章，转载请注明出处。 </strong></p>
]]></content:encoded>
			<wfw:commentRss>http://xunwap.net/archives/server-development/boost/boost-property_tree%e4%bd%bf%e7%94%a8%e7%a4%ba%e4%be%8b.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Boost中文文档</title>
		<link>http://xunwap.net/archives/server-development/boost/boost%e4%b8%ad%e6%96%87%e6%96%87%e6%a1%a3.html</link>
		<comments>http://xunwap.net/archives/server-development/boost/boost%e4%b8%ad%e6%96%87%e6%96%87%e6%a1%a3.html#comments</comments>
		<pubDate>Sat, 30 Oct 2010 06:34:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Boost]]></category>
		<category><![CDATA[Boost 中文文档]]></category>

		<guid isPermaLink="false">http://xunwap.net/?p=705</guid>
		<description><![CDATA[Boost中文文档]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste">作为STL之后又一个被广泛使用的模板库Boost，其功能和质量优异，文档有非常丰富，感谢国内的开源爱好者将Boost英文文档翻译为中文。</div>
<div id="_mcePaste">Boost中文文档下载:<a class="wp-caption" title="boost 中文文档" href="作为STL之后又一个被广泛使用的模板库Boost，其功能和质量优异，文档有非常丰富，感谢国内的开源爱好者将Boost英文文档翻译为中文。  Boost中文文档下载: http://code.google.com/p/boost-doc-zh" target="_blank"> http://code.google.com/p/boost-doc-zh</a></div>
<p style="padding-left: 390px;"><strong>本站原创文章，转载请注明出处。 </strong></p>
]]></content:encoded>
			<wfw:commentRss>http://xunwap.net/archives/server-development/boost/boost%e4%b8%ad%e6%96%87%e6%96%87%e6%a1%a3.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>boost::lexical_cast使用示例</title>
		<link>http://xunwap.net/archives/server-development/boost/boostlexical_cast%e4%bd%bf%e7%94%a8%e7%a4%ba%e4%be%8b.html</link>
		<comments>http://xunwap.net/archives/server-development/boost/boostlexical_cast%e4%bd%bf%e7%94%a8%e7%a4%ba%e4%be%8b.html#comments</comments>
		<pubDate>Fri, 22 Oct 2010 07:28:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Boost]]></category>
		<category><![CDATA[lexical_cast]]></category>

		<guid isPermaLink="false">http://xunwap.net/?p=657</guid>
		<description><![CDATA[boost::lexical_cast使用示例]]></description>
			<content:encoded><![CDATA[<p>boost::lexical_cast提供了一种简便的类型转换方法，如果int与std::string之间的转换。下面提供一个简单的例子:</p>
<pre style="color: #000000; background-color: #eeeeee; font-size: 10pt; font-family: 'Courier New';"><span style="color: #0080c0; font-weight: bold;">#include &lt;iostream&gt;</span>
<span style="color: #0080c0; font-weight: bold;">#include &lt;string&gt;</span>

<span style="color: #0080c0; font-weight: bold;">#include &lt;boost/lexical_cast.hpp&gt;</span>

<span style="color: #8080c0; font-weight: bold;">int</span> <span style="color: #004466;">main</span><span style="color: #ff0080; font-weight: bold;">(</span> <span style="color: #8080c0; font-weight: bold;">int</span> argc <span style="color: #ff0080; font-weight: bold;">,</span> <span style="color: #8080c0; font-weight: bold;">char</span> <span style="color: #ff0080; font-weight: bold;">*</span>argv<span style="color: #ff0080; font-weight: bold;">[] )</span>
<span style="color: #ff0080; font-weight: bold;">{</span>

    <span style="color: #8080c0; font-weight: bold;">int</span> iValue <span style="color: #ff0080; font-weight: bold;">=</span> <span style="color: #800080; font-weight: bold;">10</span><span style="color: #ff0080; font-weight: bold;">;</span>

    <span style="color: #8080c0; font-weight: bold;">const</span> std<span style="color: #ff0080; font-weight: bold;">::</span>string strValue <span style="color: #ff0080; font-weight: bold;">= ::</span>boost<span style="color: #ff0080; font-weight: bold;">::</span>lexical_cast<span style="color: #ff0080; font-weight: bold;">&lt;</span> std<span style="color: #ff0080; font-weight: bold;">::</span>string <span style="color: #ff0080; font-weight: bold;">&gt;(</span> iValue <span style="color: #ff0080; font-weight: bold;">);</span>
    std<span style="color: #ff0080; font-weight: bold;">::</span>cout <span style="color: #ff0080; font-weight: bold;">&lt;&lt;</span> <span style="color: #a68500;">"strValue = "</span> <span style="color: #ff0080; font-weight: bold;">&lt;&lt;</span> strValue <span style="color: #ff0080; font-weight: bold;">&lt;&lt;</span> std<span style="color: #ff0080; font-weight: bold;">::</span>endl<span style="color: #ff0080; font-weight: bold;">;</span>

    <span style="color: #8080c0; font-weight: bold;">int</span> iTarget <span style="color: #ff0080; font-weight: bold;">= ::</span>boost<span style="color: #ff0080; font-weight: bold;">::</span>lexical_cast<span style="color: #ff0080; font-weight: bold;">&lt;</span> <span style="color: #8080c0; font-weight: bold;">int</span> <span style="color: #ff0080; font-weight: bold;">&gt;(</span> strValue <span style="color: #ff0080; font-weight: bold;">);</span>
    std<span style="color: #ff0080; font-weight: bold;">::</span>cout <span style="color: #ff0080; font-weight: bold;">&lt;&lt;</span> <span style="color: #a68500;">"iTarget = "</span> <span style="color: #ff0080; font-weight: bold;">&lt;&lt;</span> iTarget <span style="color: #ff0080; font-weight: bold;">&lt;&lt;</span> std<span style="color: #ff0080; font-weight: bold;">::</span>endl<span style="color: #ff0080; font-weight: bold;">;</span>

    <span style="color: #bb7977; font-weight: bold;">return</span> <span style="color: #800080; font-weight: bold;">0</span><span style="color: #ff0080; font-weight: bold;">;</span>
<span style="color: #ff0080; font-weight: bold;">}</span></pre>
<p style="padding-left: 390px;"><strong>本站原创文章，转载请注明出处。 </strong></p>
]]></content:encoded>
			<wfw:commentRss>http://xunwap.net/archives/server-development/boost/boostlexical_cast%e4%bd%bf%e7%94%a8%e7%a4%ba%e4%be%8b.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Boost.format 使用示例</title>
		<link>http://xunwap.net/archives/server-development/boost-format-%e4%bd%bf%e7%94%a8%e7%a4%ba%e4%be%8b.html</link>
		<comments>http://xunwap.net/archives/server-development/boost-format-%e4%bd%bf%e7%94%a8%e7%a4%ba%e4%be%8b.html#comments</comments>
		<pubDate>Sat, 09 Oct 2010 15:39:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Boost]]></category>
		<category><![CDATA[Server开发]]></category>
		<category><![CDATA[format]]></category>
		<category><![CDATA[数值转换为字符串]]></category>

		<guid isPermaLink="false">http://xunwap.net/?p=555</guid>
		<description><![CDATA[本文对Boost.format的使用方法进行了举例说明。]]></description>
			<content:encoded><![CDATA[<p>通常在开发中，我们需要将数值转换为字符串进行输出和操作，在C库中我人可以使用sprintf/fprintf系统函数，在C++标准库中我们可以使用stringstream，以及本文所介绍的Boost.format类库。</p>
<p>C库中的sprintf/fprintf系统函数都针对一个指定长度的缓冲区进行操作，因此在不同的情况下设置缓冲区的长度以及缓冲区的长度而引起的缓冲区溢出问题会大大增加系统的安全隐患。</p>
<p>C++标准库中的stringstream相对于C库中的格式化函数是一个不错的选择，但是Boost.format相比于std::stringstream是一个更好的选择，因为其简单，高效且易用。<br />
下面的例子用于说明 Boost.format的使用方法:</p>
<pre style="color: #000000; background-color: #eeeeee; font-size: 10pt; font-family: '??';">boost<span style="color: #ff0080; font-weight: bold;">::</span>format 使用方法
<span style="color: #0080c0; font-weight: bold;">#include &lt;boost/format.hpp&gt;</span>
<span style="color: #0080c0; font-weight: bold;">#include &lt;string&gt;</span>
<span style="color: #0080c0; font-weight: bold;">#include &lt;stdio.h&gt;</span>

<span style="color: #8080c0; font-weight: bold;">int</span> <span style="color: #004466;">main</span><span style="color: #ff0080; font-weight: bold;">(</span> <span style="color: #8080c0; font-weight: bold;">int</span> argc <span style="color: #ff0080; font-weight: bold;">,</span> <span style="color: #8080c0; font-weight: bold;">char</span> <span style="color: #ff0080; font-weight: bold;">*</span>argv<span style="color: #ff0080; font-weight: bold;">[] )</span>
<span style="color: #ff0080; font-weight: bold;">{</span>
    <span style="color: #bb7977; font-weight: bold;">using</span> boost<span style="color: #ff0080; font-weight: bold;">::</span>format<span style="color: #ff0080; font-weight: bold;">;</span>
    boost<span style="color: #ff0080; font-weight: bold;">::</span>format <span style="color: #004466;">formater</span><span style="color: #ff0080; font-weight: bold;">(</span> <span style="color: #a68500;">"%1% %2%"</span> <span style="color: #ff0080; font-weight: bold;">);;</span>
    std<span style="color: #ff0080; font-weight: bold;">::</span>string strText <span style="color: #ff0080; font-weight: bold;">=</span> <span style="color: #004466;">str</span><span style="color: #ff0080; font-weight: bold;">(</span> formater <span style="color: #ff0080; font-weight: bold;">%</span> <span style="color: #800080; font-weight: bold;">123</span> <span style="color: #ff0080; font-weight: bold;">%</span> <span style="color: #a68500;">"number"</span> <span style="color: #ff0080; font-weight: bold;">);</span>
    <span style="color: #004466;">fprintf</span><span style="color: #ff0080; font-weight: bold;">(</span> stdout <span style="color: #ff0080; font-weight: bold;">,</span> <span style="color: #a68500;">"%s</span><span style="color: #ff00ff; font-weight: bold;">\n</span><span style="color: #a68500;">"</span> <span style="color: #ff0080; font-weight: bold;">,</span> strText<span style="color: #ff0080; font-weight: bold;">.</span><span style="color: #004466;">c_str</span><span style="color: #ff0080; font-weight: bold;">() );</span>

    strText <span style="color: #ff0080; font-weight: bold;">=</span> <span style="color: #004466;">str</span><span style="color: #ff0080; font-weight: bold;">(</span> formater <span style="color: #ff0080; font-weight: bold;">%</span> <span style="color: #a68500;">'c'</span> <span style="color: #ff0080; font-weight: bold;">%</span> <span style="color: #800080; font-weight: bold;">3.14</span> <span style="color: #ff0080; font-weight: bold;">);</span>
    <span style="color: #004466;">fprintf</span><span style="color: #ff0080; font-weight: bold;">(</span> stdout <span style="color: #ff0080; font-weight: bold;">,</span> <span style="color: #a68500;">"%s</span><span style="color: #ff00ff; font-weight: bold;">\n</span><span style="color: #a68500;">"</span> <span style="color: #ff0080; font-weight: bold;">,</span> strText<span style="color: #ff0080; font-weight: bold;">.</span><span style="color: #004466;">c_str</span><span style="color: #ff0080; font-weight: bold;">() );</span>

    <span style="color: #f27900;">// 可以直接使用 "%N%" 来指定格式化的参数是传递的参数中的哪一个</span>
    strText <span style="color: #ff0080; font-weight: bold;">=</span> <span style="color: #004466;">str</span><span style="color: #ff0080; font-weight: bold;">(</span> boost<span style="color: #ff0080; font-weight: bold;">::</span><span style="color: #004466;">format</span><span style="color: #ff0080; font-weight: bold;">(</span> <span style="color: #a68500;">"%1% %1% %2% %2%"</span> <span style="color: #ff0080; font-weight: bold;">) %</span> <span style="color: #800080; font-weight: bold;">1</span> <span style="color: #ff0080; font-weight: bold;">%</span> <span style="color: #800080; font-weight: bold;">2</span> <span style="color: #ff0080; font-weight: bold;">);</span>
    <span style="color: #004466;">fprintf</span><span style="color: #ff0080; font-weight: bold;">(</span> stdout <span style="color: #ff0080; font-weight: bold;">,</span> <span style="color: #a68500;">"%s</span><span style="color: #ff00ff; font-weight: bold;">\n</span><span style="color: #a68500;">"</span> <span style="color: #ff0080; font-weight: bold;">,</span> strText<span style="color: #ff0080; font-weight: bold;">.</span><span style="color: #004466;">c_str</span><span style="color: #ff0080; font-weight: bold;">() );</span>

    <span style="color: #f27900;">// 也可以使用 "%s %d %f" 之类的printf格式的格式化字符指令来确定指定的参数被格式化的形式</span>
    strText <span style="color: #ff0080; font-weight: bold;">=</span> <span style="color: #004466;">str</span><span style="color: #ff0080; font-weight: bold;">(</span> boost<span style="color: #ff0080; font-weight: bold;">::</span><span style="color: #004466;">format</span><span style="color: #ff0080; font-weight: bold;">(</span> <span style="color: #a68500;">"%s , %d , %f"</span> <span style="color: #ff0080; font-weight: bold;">) %</span> <span style="color: #a68500;">"abc"</span> <span style="color: #ff0080; font-weight: bold;">%</span> <span style="color: #800080; font-weight: bold;">123</span> <span style="color: #ff0080; font-weight: bold;">%</span> <span style="color: #800080; font-weight: bold;">456.7</span> <span style="color: #ff0080; font-weight: bold;">);</span>
    <span style="color: #004466;">fprintf</span><span style="color: #ff0080; font-weight: bold;">(</span> stdout <span style="color: #ff0080; font-weight: bold;">,</span> <span style="color: #a68500;">"%s</span><span style="color: #ff00ff; font-weight: bold;">\n</span><span style="color: #a68500;">"</span> <span style="color: #ff0080; font-weight: bold;">,</span> strText<span style="color: #ff0080; font-weight: bold;">.</span><span style="color: #004466;">c_str</span><span style="color: #ff0080; font-weight: bold;">() );</span>

    <span style="color: #f27900;">// 使用 "%N%" 比 "%flag" 的好处在于，前者可以在格式化时对传递进来的参数使用多次.</span>

    formater <span style="color: #ff0080; font-weight: bold;">%</span> <span style="color: #800080; font-weight: bold;">9</span><span style="color: #ff0080; font-weight: bold;">;</span>

    <span style="color: #f27900;">// 清除之前传入的参数 "9"</span>
    formater<span style="color: #ff0080; font-weight: bold;">.</span><span style="color: #004466;">clear</span><span style="color: #ff0080; font-weight: bold;">();</span>
    formater <span style="color: #ff0080; font-weight: bold;">%</span> <span style="color: #800080; font-weight: bold;">1234</span> <span style="color: #ff0080; font-weight: bold;">%</span> <span style="color: #800080; font-weight: bold;">5678</span><span style="color: #ff0080; font-weight: bold;">;</span>
    <span style="color: #004466;">fprintf</span><span style="color: #ff0080; font-weight: bold;">(</span> stdout <span style="color: #ff0080; font-weight: bold;">,</span> <span style="color: #a68500;">"%s</span><span style="color: #ff00ff; font-weight: bold;">\n</span><span style="color: #a68500;">"</span> <span style="color: #ff0080; font-weight: bold;">,</span> formater<span style="color: #ff0080; font-weight: bold;">.</span><span style="color: #004466;">str</span><span style="color: #ff0080; font-weight: bold;">().</span><span style="color: #004466;">c_str</span><span style="color: #ff0080; font-weight: bold;">() );</span>

    <span style="color: #f27900;">// 改变其中的某个传入的参数</span>
    formater <span style="color: #ff0080; font-weight: bold;">%</span> <span style="color: #800080; font-weight: bold;">12</span> <span style="color: #ff0080; font-weight: bold;">%</span> <span style="color: #800080; font-weight: bold;">34</span><span style="color: #ff0080; font-weight: bold;">;</span>
    formater<span style="color: #ff0080; font-weight: bold;">.</span><span style="color: #004466;">bind_arg</span><span style="color: #ff0080; font-weight: bold;">(</span> <span style="color: #800080; font-weight: bold;">1</span> <span style="color: #ff0080; font-weight: bold;">,</span> <span style="color: #800080; font-weight: bold;">6666</span> <span style="color: #ff0080; font-weight: bold;">);</span>
    <span style="color: #004466;">fprintf</span><span style="color: #ff0080; font-weight: bold;">(</span> stdout <span style="color: #ff0080; font-weight: bold;">,</span> <span style="color: #a68500;">"%s</span><span style="color: #ff00ff; font-weight: bold;">\n</span><span style="color: #a68500;">"</span> <span style="color: #ff0080; font-weight: bold;">,</span> formater<span style="color: #ff0080; font-weight: bold;">.</span><span style="color: #004466;">str</span><span style="color: #ff0080; font-weight: bold;">().</span><span style="color: #004466;">c_str</span><span style="color: #ff0080; font-weight: bold;">() );</span>

    <span style="color: #f27900;">// 一旦格式化成功之后，如果调用任何的函数获取了其中的"格式化之后的字符串"，那么这个格式化的字符串将不能再进行参数的修改了，</span>
    <span style="color: #f27900;">// 直到下一次调用 "%" 传入参数开始，之前被格式化的参数将会被清除，以新传入的参数进行新的格式化操作.</span>

    <span style="color: #bb7977; font-weight: bold;">return</span> <span style="color: #800080; font-weight: bold;">0</span><span style="color: #ff0080; font-weight: bold;">;</span>
<span style="color: #ff0080; font-weight: bold;">}</span></pre>
<p style="padding-left: 390px;"><strong>本站原创文章，转载请注明出处。 </strong></p>
]]></content:encoded>
			<wfw:commentRss>http://xunwap.net/archives/server-development/boost-format-%e4%bd%bf%e7%94%a8%e7%a4%ba%e4%be%8b.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

