Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r48807 - sandbox/committee/concepts/stdlib
From: dgregor_at_[hidden]
Date: 2008-09-17 01:28:06


Author: dgregor
Date: 2008-09-17 01:28:05 EDT (Wed, 17 Sep 2008)
New Revision: 48807
URL: http://svn.boost.org/trac/boost/changeset/48807

Log:
Add substr
Added:
   sandbox/committee/concepts/stdlib/substr.sty (contents, props changed)

Added: sandbox/committee/concepts/stdlib/substr.sty
==============================================================================
--- (empty file)
+++ sandbox/committee/concepts/stdlib/substr.sty 2008-09-17 01:28:05 EDT (Wed, 17 Sep 2008)
@@ -0,0 +1,184 @@
+%%
+%% substr.sty
+%%
+%% This package provides commands to deal with substrings in strings:
+%% Determine if a string contains a substring, count appearances of a
+%% substring in a string.
+%%
+%%
+%% Commands:
+%%
+%% \IfSubStringInString{substring}{string}{true part}{false part}
+%% This command searches <substring> in <string> and executes the
+%% <true part> if it is and else the <else part>
+%%
+%% \IfCharInString{char}{string}{true part}{false part}
+%% Actualy the same as \IfSubStringInString.
+%%
+%% \BehindSubString{substring}{string}
+%% Returns the part of <string> that is on the behind
+%% <substring>. Always the first appearance of <substring> is taken.
+%%
+%% \BeforeSubString{substring}{string}
+%% Returns the part of <string> that is on the before
+%% <substring>. Always the first appearance of <substring> is taken.
+%%
+%% \CountSubStrings{substring}{string}
+%% Counts the number of appearances of <substring> in <string> and
+%% returns it as text.
+%%
+%% \SubStringsToCounter{counter}{substring}{string}
+%% Counts the number of appearances of <substring> in <string> and
+%% sets the counter <counter> to that value.
+%%
+%% \IfBeforeSubStringEmpty{substring}{string}{true part}{false part}
+%% Calls <true part> if <substring> is equal to the beginning of <string>.
+%% Else call <false part>.
+%%
+%% \IfBehindSubStringEmpty{substring}{string}{true part}{false part}
+%% Calls <true part> if <substring> is equal to the end of <string>.
+%% Else call <false part>.
+%%
+%%
+%% History of this package:
+%%
+%% The package arises from a posting of me in the newsgroup
+%% de.comp.text.tex in which I asked how to find out if a substring
+%% is included in a string. Heiko Oberdiek
+%% <oberdiek_at_[hidden]> posted the commands
+%% \IfSubStringInString and \IfCharInString and suggested to write a
+%% command which counts the appearances in a string. So, I wrote the
+%% commands \CountSubStrings and \SubStringsToCounter.
+%% After I wrote this package I sent it to Heiko Oberdiek
+%% who improved and rewrote many parts of it.
+%%
+%%
+%% Copyright 2000, 2005 Harald Harders
+%%
+%% This program can be redistributed and/or modified under the terms
+%% of the LaTeX Project Public License Distributed from CTAN
+%% archives in directory macros/latex/base/lppl.txt; either
+%% version 1 of the License, or any later version.
+%%
+%%
+%% 2005-11-29
+%% Harald Harders
+%% h.harders_at_[hidden]
+%%
+\ProvidesPackage{substr}[2005/11/29 v1.1 Handle substrings]
+%%
+% expands the first and second argument with
+% \protected_at_edef and calls #3 with them:
+\newcommand\su_at_ExpandTwoArgs[3]{%
+ \protected_at_edef\su_at_SubString{#1}%
+ \protected_at_edef\su_at_String{#2}%
+ \expandafter\expandafter\expandafter#3%
+ \expandafter\expandafter\expandafter{%
+ \expandafter\su_at_SubString\expandafter
+ }\expandafter{\su_at_String}%
+}
+%%
+%% tests if #1 in #2. If yes execute #3, else #4
+\newcommand*\IfSubStringInString[2]{%
+ \su_at_ExpandTwoArgs{#1}{#2}\su_at_IfSubStringInString
+}
+%%
+\newcommand*\su_at_IfSubStringInString[2]{%
+ \def\su_at_compare##1#1##2\@nil{%
+ \def\su_at_param{##2}%
+ \ifx\su_at_param\@empty
+ \expandafter\@secondoftwo
+ \else
+ \expandafter\@firstoftwo
+ \fi
+ }%
+ \su_at_compare#2#1\@nil
+}
+%%
+%% tests if #1 in #2. If yes execute #3, else #4
+\newcommand\IfCharInString{}
+\let\IfCharInString\IfSubStringInString
+%%
+%% returns the part of the string behind the found substring
+\newcommand*\BehindSubString[2]{%
+ \su_at_ExpandTwoArgs{#1}{#2}\su_at_BehindSubString
+}
+\newcommand*\su_at_BehindSubString[2]{%
+ \def\su_at_rest##1#1##2\@nil{##2}%
+ \IfSubStringInString{#1}{#2}{\su_at_rest#2\@nil}{}%
+}
+%%
+%% returns the part of the string before the found substring
+\newcommand*\BeforeSubString[2]{%
+ \su_at_ExpandTwoArgs{#1}{#2}\su_at_BeforeSubString
+}
+\newcommand*\su_at_BeforeSubString[2]{%
+ \def\su_at_rest##1#1##2\@nil{##1}%
+ \IfSubStringInString{#1}{#2}{\su_at_rest#2\@nil}{#2}%
+}
+%%
+%% calls #3 if part of string before substring is empty, otherwise calls #4.
+\newcommand*\IfBeforeSubStringEmpty[2]{%
+ \su_at_ExpandTwoArgs{#1}{#2}\su_at_IfBeforeSubStringEmpty
+}
+%%
+\newcommand*\su_at_IfBeforeSubStringEmpty[4]{%
+ \def\su_at_rest##1#1##2\@nil{##1}%
+ \IfSubStringInString{#1}{#2}{%
+ \edef\su_at_resta{\su_at_rest#2\@nil}%
+ \ifx\@empty\su_at_resta #3\else #4\fi
+ }{#4}%
+}
+%%
+%% calls #3 if part of string after substring is empty, otherwise calls #4.
+\newcommand*\IfBehindSubStringEmpty[2]{%
+ \su_at_ExpandTwoArgs{#1}{#2}\su_at_IfBehindSubStringEmpty
+}
+%%
+\newcommand*\su_at_IfBehindSubStringEmpty[4]{%
+ \def\su_at_rest##1#1##2\@nil{##2}%
+ \IfSubStringInString{#1}{#2}{%
+ \edef\su_at_resta{\su_at_rest#2\@nil}%
+ \ifx\@empty\su_at_resta #3\else #4\fi
+ }{#4}%
+}
+%%
+%% counter for counting appearances
+\newcounter{su_at_anzahl}
+%%
+% #1: String
+% #2: Substring
+% #3: Counter
+\newcommand*\su_at_StringSubstringCounter[3]{%
+ \su_at_IfSubStringInString{#2}{#1}{%
+ \stepcounter{#3}%
+ \def\su_at_rest##1#2##2\@nil{##2}%
+ \expandafter\su_at_StringSubstringCounter\expandafter
+ {\su_at_rest#1\@nil}{#2}{#3}%
+ }{}%
+}
+%%
+\newcommand*\CountSubStrings[2]{%
+ \su_at_ExpandTwoArgs{#1}{#2}\su_at_CountSubStrings
+}
+\newcommand*\su_at_CountSubStrings[2]{%
+ \setcounter{su_at_anzahl}{0}%
+ \su_at_StringSubstringCounter{#2}{#1}{su_at_anzahl}%
+ \thesu_at_anzahl
+}
+% #1: counter
+% #2: substring
+% #3: string
+\newcommand*\SubStringsToCounter[3]{%
+ \su_at_ExpandTwoArgs{#2}{#3}\su_at_SubStringsToCounter{#1}%
+}
+% #1: substring
+% #2: string
+% #3: counter
+\newcommand*\su_at_SubStringsToCounter[3]{%
+ \setcounter{#3}{0}%
+ \su_at_StringSubstringCounter{#2}{#1}{#3}%
+}
+%%
+\endinput
+%% EOF


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk