From f18ee8bb402e5cff7b3513c0e7390020b7b09945 Mon Sep 17 00:00:00 2001 From: tjr Date: Thu, 3 Oct 2002 08:49:29 +0000 Subject: Add an Examples section with an example of how to use the functions. --- lib/libc/locale/wctrans.3 | 16 +++++++++++++++- lib/libc/locale/wctype.3 | 16 +++++++++++++++- lib/libc/locale/wcwidth.3 | 25 ++++++++++++++++++++++++- 3 files changed, 54 insertions(+), 3 deletions(-) (limited to 'lib/libc/locale') diff --git a/lib/libc/locale/wctrans.3 b/lib/libc/locale/wctrans.3 index 5f491a6..0941e80 100644 --- a/lib/libc/locale/wctrans.3 +++ b/lib/libc/locale/wctrans.3 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd August 4, 2002 +.Dd October 3, 2002 .Dt WCTRANS 3 .Os .Sh NAME @@ -71,6 +71,20 @@ The function returns non-zero if successful, otherwise it returns zero and sets .Va errno . +.Sh EXAMPLES +Reimplement +.Fn towupper +in terms of +.Fn towctrans +and +.Fn wctrans : +.Bd -literal -offset indent +wint_t +mytowupper(wint_t wc) +{ + return (towctrans(wc, wctrans("toupper"))); +} +.Ed .Sh ERRORS The .Fn towctrans diff --git a/lib/libc/locale/wctype.3 b/lib/libc/locale/wctype.3 index f23745b..7843af7 100644 --- a/lib/libc/locale/wctype.3 +++ b/lib/libc/locale/wctype.3 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd August 3, 2002 +.Dd October 3, 2002 .Dt WCTYPE 3 .Os .Sh NAME @@ -80,6 +80,20 @@ is invalid, otherwise it returns a value of type .Vt wctype_t that can be used in subsequent calls to .Fn iswctype . +.Sh EXAMPLES +Reimplement +.Fn iswalpha +in terms of +.Fn iswctype +and +.Fn wctype : +.Bd -literal -offset indent +int +myiswalpha(wint_t wc) +{ + return (iswctype(wc, wctype("alpha"))); +} +.Ed .Sh SEE ALSO .Xr ctype 3 .Sh STANDARDS diff --git a/lib/libc/locale/wcwidth.3 b/lib/libc/locale/wcwidth.3 index b651368..78c969e 100644 --- a/lib/libc/locale/wcwidth.3 +++ b/lib/libc/locale/wcwidth.3 @@ -23,7 +23,7 @@ .\" SUCH DAMAGE. .\" .\" $FreeBSD$ -.Dd August 18, 2002 +.Dd October 3, 2002 .Dt WCWIDTH 3 .Os .Sh NAME @@ -52,6 +52,29 @@ argument is a null wide character (L'\e0'), is not printable, otherwise it returns the number of column positions the character occupies. +.Sh EXAMPLES +This code fragment reads text from standard input and +breaks lines that are more than 20 column positions wide, +similar to the +.Xr fold 1 +utility: +.Bd -literal -offset indent +wint_t ch; +int column, w; + +column = 0; +while ((ch = getwchar()) != WEOF) { + if ((w = wcwidth(ch)) > 0) + column += w; + if (column >= 20) { + putwchar(L'\n'); + column = 0; + } + putwchar(ch); + if (ch == L'\n') + column = 0; +} +.Ed .Sh SEE ALSO .Xr iswprint 3 , .Xr wcswidth 3 -- cgit v1.1