From 8c14b1452075b92517dbfae956722cb9564d562b Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Fri, 13 Jan 2006 00:08:08 +0000 Subject: substr git-svn-id: svn://tug.org/texlive/trunk@1357 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/tex/latex/substr/substr.sty | 150 ++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 Master/texmf-dist/tex/latex/substr/substr.sty (limited to 'Master/texmf-dist/tex/latex/substr') diff --git a/Master/texmf-dist/tex/latex/substr/substr.sty b/Master/texmf-dist/tex/latex/substr/substr.sty new file mode 100644 index 00000000000..1537f872fba --- /dev/null +++ b/Master/texmf-dist/tex/latex/substr/substr.sty @@ -0,0 +1,150 @@ +%% +%% 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 in and executes the +%% if it is and else the +%% +%% \IfCharInString{char}{string}{true part}{false part} +%% Actualy the same as \IfSubStringInString. +%% +%% \BehindSubString{substring}{string} +%% Returns the part of that is on the behind +%% . Always the first appearance of is taken. +%% +%% \BeforeSubString{substring}{string} +%% Returns the part of that is on the before +%% . Always the first appearance of is taken. +%% +%% \CountSubStrings{substring}{string} +%% Counts the number of appearances of in and +%% returns it as text. +%% +%% \SubStringsToCounter}{counter}{substring}{string} +%% Counts the number of appearances of in and +%% sets the counter to that value. +%% +%% +%% 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 +%% 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 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. +%% +%% +%% 2000-06-15 +%% Harald Harders +%% h.harders@tu-bs.de +%% +\ProvidesPackage{substr}[2000/06/15] +%% +% expands the first and second argument with +% \protected@edef and calls #3 with them: +\newcommand{\su@ExpandTwoArgs}[3]{% + \protected@edef\su@SubString{#1}% + \protected@edef\su@String{#2}% + \expandafter\expandafter\expandafter#3% + \expandafter\expandafter\expandafter{% + \expandafter\su@SubString\expandafter + }\expandafter{\su@String}% +} +%% +%% tests if #1 in #2. If yes execute #3, else #4 +\newcommand*{\IfSubStringInString}[2]{% + \su@ExpandTwoArgs{#1}{#2}\su@IfSubStringInString +} +%% +\newcommand*{\su@IfSubStringInString}[2]{% + \def\su@compare##1#1##2\@nil{% + \def\su@param{##2}% + \ifx\su@param\@empty + \expandafter\@secondoftwo + \else + \expandafter\@firstoftwo + \fi + }% + \su@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@ExpandTwoArgs{#1}{#2}\su@BehindSubString +} +\newcommand*{\su@BehindSubString}[2]{% + \def\su@rest##1#1##2\@nil{##2}% + \IfSubStringInString{#1}{#2}{\su@rest#2\@nil}{}% +} +%% +%% returns the part of the string before the found substring +\newcommand*{\BeforeSubString}[2]{% + \su@ExpandTwoArgs{#1}{#2}\su@BeforeSubString +} +\newcommand*{\su@BeforeSubString}[2]{% + \def\su@rest##1#1##2\@nil{##1}% + \IfSubStringInString{#1}{#2}{\su@rest#2\@nil}{#2}% +} +%% +%% counter for counting appearances +\newcounter{su@anzahl} +%% +% #1: String +% #2: Substring +% #3: Counter +\newcommand*{\su@StringSubstringCounter}[3]{% + \su@IfSubStringInString{#2}{#1}{% + \stepcounter{#3}% + \def\su@rest##1#2##2\@nil{##2}% + \expandafter\su@StringSubstringCounter\expandafter + {\su@rest#1\@nil}{#2}{#3}% + }{}% +} +%% +\newcommand*{\CountSubStrings}[2]{% + \su@ExpandTwoArgs{#1}{#2}\su@CountSubStrings +} +\newcommand*{\su@CountSubStrings}[2]{% + \setcounter{su@anzahl}{0}% + \su@StringSubstringCounter{#2}{#1}{su@anzahl}% + \thesu@anzahl +} +% #1: counter +% #2: substring +% #3: string +\newcommand*{\SubStringsToCounter}[3]{% + \su@ExpandTwoArgs{#2}{#3}\su@SubStringsToCounter{#1}% +} +% #1: substring +% #2: string +% #3: counter +\newcommand*{\su@SubStringsToCounter}[3]{% + \setcounter{#3}{0}% + \su@StringSubstringCounter{#2}{#1}{#3}% +} +%% +\endinput +%% EOF -- cgit v1.2.3