blob: 8ef68b528aafd734ec5706e24764a6292fd23dc5 [file] [log] [blame]
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed
with this work for additional information regarding copyright
ownership. The ASF 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
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.
Copyright 1999-2007 Rogue Wave Software, Inc.
-->
<HTML>
<HEAD>
<TITLE>An Example of Formatting Phone Numbers</TITLE>
<LINK REL=StyleSheet HREF="../rw.css" TYPE="text/css" TITLE="Apache stdcxx Stylesheet"></HEAD>
<BODY BGCOLOR=#FFFFFF>
<A HREF="26.html"><IMG SRC="images/bprev.gif" WIDTH=20 HEIGHT=21 ALT="Previous file" BORDER=O></A><A HREF="noframes.html"><IMG SRC="images/btop.gif" WIDTH=56 HEIGHT=21 ALT="Top of Document" BORDER=O></A><A HREF="booktoc.html"><IMG SRC="images/btoc.gif" WIDTH=56 HEIGHT=21 ALT="Contents" BORDER=O></A><A HREF="tindex.html"><IMG SRC="images/bindex.gif" WIDTH=56 HEIGHT=21 ALT="Index page" BORDER=O></A><A HREF="26-2.html"><IMG SRC="images/bnext.gif" WIDTH=25 HEIGHT=21 ALT="Next file" BORDER=O></A><DIV CLASS="DOCUMENTNAME"><B>Apache C++ Standard Library User's Guide</B></DIV>
<H2>26.1 An Example of Formatting Phone Numbers</H2>
<A NAME="idx585"><!></A>
<A NAME="idx586"><!></A>
<P>The previous chapters explained how you can use locales and the standard facet classes, and how you can build new facet classes. This chapter introduces you to the technique of building your own facet class and using it in conjunction with the input/output streams of the C++ Standard Library, the iostreams. This material is rather advanced, and requires some knowledge of standard iostreams.</P>
<A NAME="idx587"><!></A>
<P>In the following sections, we will work through a complete example on formatting telephone numbers. Formatting telephone numbers involves local conventions that vary from culture to culture. For example, the same US phone number can have all of the formats listed below:</P>
<TABLE BORDER="0" CELLPADDING="3" CELLSPACING="3">
<tr><td valign=top><P CLASS="TABLE">754-3010</P>
</td><td valign=top><P CLASS="TABLE">Local</P>
</td></tr>
<tr><td valign=top><P CLASS="TABLE">(541) 754-3010</P>
</td><td valign=top><P CLASS="TABLE">Domestic</P>
</td></tr>
<tr><td valign=top><P CLASS="TABLE">+1-541-754-3010</P>
</td><td valign=top><P CLASS="TABLE">International</P>
</td></tr>
<tr><td valign=top><P CLASS="TABLE">1-541-754-3010</P>
</td><td valign=top><P CLASS="TABLE">Dialed in the US</P>
</td></tr>
<tr><td valign=top><P CLASS="TABLE">001-541-754-3010</P>
</td><td valign=top><P CLASS="TABLE">Dialed from Germany</P>
</td></tr>
<tr><td valign=top><P CLASS="TABLE">191 541 754 3010</P>
</td><td valign=top><P CLASS="TABLE">Dialed from France</P>
</td></tr>
</TABLE>
<P>Now consider a German phone number. Although a German phone number consists of an area code and an extension like a US number, the format is different. Here is the same German phone number in a variety of formats:</P>
<TABLE BORDER="0" CELLPADDING="3" CELLSPACING="3">
<tr><td valign=top><P CLASS="TABLE">636-48018</P>
</td><td valign=top><P CLASS="TABLE">Local</P>
</td></tr>
<tr><td valign=top><P CLASS="TABLE">(089) / 636-48018</P>
</td><td valign=top><P CLASS="TABLE">Domestic</P>
</td></tr>
<tr><td valign=top><P CLASS="TABLE">+49-89-636-48018</P>
</td><td valign=top><P CLASS="TABLE">International</P>
</td></tr>
<tr><td valign=top><P CLASS="TABLE">19-49-89-636-48018</P>
</td><td valign=top><P CLASS="TABLE">Dialed from France</P>
</td></tr>
</TABLE>
<P>Note the difference in formatting domestic numbers. In the US, the convention is <SAMP>1 (area code) extension</SAMP>, while in Germany it is <SAMP>(0 area code)/extension</SAMP>.</P>
<BR>
<HR>
<A HREF="26.html"><IMG SRC="images/bprev.gif" WIDTH=20 HEIGHT=21 ALT="Previous file" BORDER=O></A><A HREF="noframes.html"><IMG SRC="images/btop.gif" WIDTH=56 HEIGHT=21 ALT="Top of Document" BORDER=O></A><A HREF="booktoc.html"><IMG SRC="images/btoc.gif" WIDTH=56 HEIGHT=21 ALT="Contents" BORDER=O></A><A HREF="tindex.html"><IMG SRC="images/bindex.gif" WIDTH=56 HEIGHT=21 ALT="Index page" BORDER=O></A><A HREF="26-2.html"><IMG SRC="images/bnext.gif" WIDTH=20 HEIGHT=21 ALT="Next file" BORDER=O></A>
<!-- Google Analytics tracking code -->
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-1775151-1";
urchinTracker();
</script>
<!-- end of Google Analytics tracking code -->
</BODY>
</HTML>