From c7a76f56847244cd1a2206a8cd63aadc943dad05 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Mon, 15 Jan 2007 01:13:25 +0000 Subject: coolstr update git-svn-id: svn://tug.org/texlive/trunk@3491 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/source/latex/coolstr/coolstr.dtx | 210 ++++++++++++++++++++- Master/texmf-dist/source/latex/coolstr/coolstr.ins | 78 ++++---- 2 files changed, 239 insertions(+), 49 deletions(-) (limited to 'Master/texmf-dist/source/latex/coolstr') diff --git a/Master/texmf-dist/source/latex/coolstr/coolstr.dtx b/Master/texmf-dist/source/latex/coolstr/coolstr.dtx index cb3c9b895a6..1211a996321 100644 --- a/Master/texmf-dist/source/latex/coolstr/coolstr.dtx +++ b/Master/texmf-dist/source/latex/coolstr/coolstr.dtx @@ -2,7 +2,7 @@ % %\NeedsTeXFormat{LaTeX2e}[1999/12/01] %\ProvidesPackage{coolstr} -% [2006/12/30 v2.0a COntent Oriented LaTeX Strings] +% [2007/01/08 v2.1 COntent Oriented LaTeX Strings] %\RequirePackage{ifthen} %\RequirePackage{amsmath} %\RequirePackage{amssymb} @@ -22,7 +22,7 @@ % \fi % % -% \CheckSum{218} +% \CheckSum{309} % % %% \CharacterTable @@ -50,7 +50,7 @@ % \DoNotIndex{\@ne,\expandafter} % \DoNotIndex{\advance,\begingroup,\catcode,\closein} % \DoNotIndex{\newcommand,\renewcommand,\providecommand} -% \DoNotIndex{\closeout,\day,\def,\edef,\gdef,\let,\empty,\endgroup} +% \DoNotIndex{\closeout,\day,\def,\edef,\gdef,\xdef,\let,\empty,\endgroup} % \DoNotIndex{\newcounter,\providecounter,\addtocounter,\setcounter,\stepcounter,\value,\arabic} % \DoNotIndex{\if,\fi,\ifthenelse,\else,\setboolean,\boolean,\newboolean,\provideboolean,\equal,\AND,\OR,\NOT,\whiledo} % \DoNotIndex{\ifcase,\ifcat,\or,\else} @@ -97,10 +97,60 @@ % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%\section{Descriptions} +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% \DescribeMacro{\substr} |\substr|\marg{string}\marg{start index}\marg{num char} gives at most $\|$\meta{num char}$\|$ +% characters from \meta{string}. +% +% if \meta{start index} is greater than zero, and \meta{num char} is greater than zero, |\substr| gives at most +% \meta{num char} starting with index \meta{start index} and going to the end of the string. +% +% if \meta{start index} is greater than zero, and \meta{num char} is less than zero, |\substr| gives at most +% $-$\meta{num char} characters and going to the beginning of the string +% +% if \meta{start index} is less than zero, and \meta{num char} is greater than zero, |\substr| gives at most +% \meta{num char} characters starting at the $-$\meta{start index} character from the end of the string and going +% to the end of the string +% +% if \meta{start index} is less than zero, and \meta{num char} is less than zero, |\substr| gives at most +% $-$\meta{num char} characters starting at the $-$\meta{start index} character from the end of the string and going +% to the beginning of the string +% +% There are two special, non-numeric values that \meta{char num} may take. They are |end| or |beg|, and they will always +% go to the end or begining of the string, respectively +% +% +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\section{Test Cases} % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % +%\subsection{\texttt{$\backslash$substr}} +% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% \DescribeMacro{\substr} +% +% \begin{tabular}{ll} +% \hline +% |\substr{12345}{1}{2}| & \substr{12345}{1}{2} \\ +% |\substr{12345}{3}{5}| & \substr{12345}{3}{5} \\ +% |\substr{12345}{3}{end}| & \substr{12345}{3}{end} \\ +% |\substr{12345}{3}{beg}| & \substr{12345}{3}{beg} \\ +% |\substr{12345}{-2}{1}| & \substr{12345}{-2}{1} \\ +% |\substr{12345}{3}{-2}| & \substr{12345}{3}{-2} \\ +% |\substr{12345}{-2}{-2}| & \substr{12345}{-2}{-2} \\ +% |\substr{12345}{0}{5}| & \substr{12345}{0}{5} (the null string) \\ +% |\substr{12345}{2}{0}| & \substr{12345}{2}{0} (the null string) \\ +% \hline +% \end{tabular} +% +% % \newboolean{t} % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -187,7 +237,7 @@ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% Thanks to J.~J.~Weimer for the comments and aid in coding. +% Thanks to J.~J.~Weimer for the comments and aid in coding. Also thanks goes to Abraham Weishaus for pointing out a bug in |\strlenstore| % % % @@ -278,14 +328,22 @@ % % \begin{macro}{\strlen} % \changes{v2.0}{2006/12/29}{added to package} +% \changes{v2.1}{2007/01/08}{added ifthenelse to return $0$ for empty string} % |\strlen|\marg{string} gives the length of the string. It is better to use |\strlenstore| to record the length % % |\strlen{abc}| \strlen{abc} % % \begin{macrocode} \newcommand{\strlen}[1]{% -\strchar{#1}{0} -\arabic{COOL@strpointer}% +\ifthenelse{\equal{#1}{}}% + {% + 0% + }% +% Else + {% + \strchar{#1}{0}% + \arabic{COOL@strpointer}% + }% } % \end{macrocode} % @@ -294,12 +352,143 @@ % % \begin{macro}{\strlenstore} % \changes{v2.0}{2006/12/29}{added to package} +% \changes{v2.1}{2007/01/08}{corrected error in setting counter} +% \changes{v2.1}{2007/01/08}{added ifthenelse to return $0$ for empty string} % |\strlenstore|\marg{string}\marg{counter} stores the length of \meta{string} in \meta{counter} % % \begin{macrocode} \newcommand{\strlenstore}[2]{% -\strchar{#1}{0}% -\setcounter{#2}{COOL@strpointer}% +\ifthenelse{\equal{#1}{}}% + {% + \setcounter{#2}{0}% + }% +% Else + {% + \strchar{#1}{0}% + \setcounter{#2}{\value{COOL@strpointer}}% + }% +} +% \end{macrocode} +% +% \end{macro} +% +% +% +% +% \begin{macro}{\substr} +% \changes{v2.1}{2007/01/08}{added to package} +% |\substr|\marg{string}\marg{index}\marg{numchar} +% +% a special value of |end| for \meta{numchar} gives from \meta{index} to the end of the string; |beg| gives from \meta{index} to the beginning of the string +% +% \begin{macrocode} +\newcounter{COOL@str@index} +\newcounter{COOL@str@start} +\newcounter{COOL@str@end} +\newcommand{\substr}[3]{% +\strlenstore{#1}{COOL@strlen}% +\ifthenelse{#2 < 0 \AND \NOT #2 < -\value{COOL@strlen}}% + {% +% \end{macrocode} +% The starting index is less than zero, so start that many characters back from the end. This means mapping the index to \meta{index}${} + {}$\meta{string length}${} + 1$ +% \begin{macrocode} + \setcounter{COOL@str@index}{\value{COOL@strlen}}% + \addtocounter{COOL@str@index}{#2}% + \addtocounter{COOL@str@index}{1}% + }% +% ElseIf +{\ifthenelse{#2 > 0 \AND \NOT #2 > \value{COOL@strlen}}% + {% +% \end{macrocode} +% The starting index is greater than zero, and within the appropriate range; record it +% \begin{macrocode} + \setcounter{COOL@str@index}{#2}% + }% +% Else + {% +% \end{macroccode} +% The \meta{index} value is invalid. Set it to zero for returning the null string +% \begin{macrocode} + \setcounter{COOL@str@index}{0}% + }}% +% \end{macrocode} +% Now deal with the \meta{numchar} (which can also be negative) +% \begin{macrocode} +\ifthenelse{\equal{#3}{beg}}% + {% + \setcounter{COOL@str@start}{1}% + \setcounter{COOL@str@end}{\value{COOL@str@index}}% + }% +% ElseIf +{\ifthenelse{\equal{#3}{end}}% + {% + \setcounter{COOL@str@start}{\value{COOL@str@index}}% + \setcounter{COOL@str@end}{\value{COOL@strlen}}% + }% +% ElseIf +{\ifthenelse{#3 < 0}% + {% +% \end{macrocode} +% This means to take that many characters to the \emph{left} of the starting index. +% \begin{macrocode} + \setcounter{COOL@str@start}{\value{COOL@str@index}}% + \addtocounter{COOL@str@start}{#3}% + \addtocounter{COOL@str@start}{1}% + \ifthenelse{\NOT \value{COOL@str@start} > 0}{\setcounter{COOL@str@start}{1}}{}% + \setcounter{COOL@str@end}{\value{COOL@str@index}}% + }% +% ElseIf +{\ifthenelse{#3 > 0}% + {% + \setcounter{COOL@str@start}{\value{COOL@str@index}}% + \setcounter{COOL@str@end}{\value{COOL@str@index}}% + \addtocounter{COOL@str@end}{#3}% + \addtocounter{COOL@str@end}{-1}% + \ifthenelse{\value{COOL@str@end} > \value{COOL@strlen}}{\setcounter{COOL@str@end}{\value{COOL@strlen}}}{}% + }% +% Else + {% +% \end{macrocode} +% nonsense submitted, so return the null string +% \begin{macrocode} + \setcounter{COOL@str@index}{0}% + }}}}% +% \end{macrocode} +% Now send back the appropriate thing +% \begin{macrocode} +\ifthenelse{ \value{COOL@str@index} = 0 }% + {% + }% +% Else + {% + \setcounter{COOL@strpointer}{1}% + \COOL@substrgobbler#1\COOL@strStop\COOL@strEnd% + }% +} +% \end{macrocode} +% Now define the ``gobbler" +% \begin{macrocode} +\def\COOL@substrgobbler#1#2\COOL@strEnd{% +\ifthenelse{\equal{#2}{\COOL@strStop}}% + {% + \ifthenelse{ \value{COOL@strpointer} < \value{COOL@str@start} \OR \value{COOL@strpointer} > \value{COOL@str@end} }% + {}% + % Else + {% + #1% + }% + }% +% Else + {% + \ifthenelse{ \value{COOL@strpointer} < \value{COOL@str@start} \OR \value{COOL@strpointer} > \value{COOL@str@end} }% + {}% + % Else + {% + #1% + }% + \stepcounter{COOL@strpointer}% + \COOL@substrgobbler#2\COOL@strEnd% + }% } % \end{macrocode} % @@ -374,11 +563,12 @@ % \noindent |\ifstrleneq{abcde}{3}{length is $3$}{length is not $3$}| \ifstrleneq{abcde}{3}{length is $3$}{length is not $3$} % % \changes{v2.0}{2006/12/29}{added to package to do length comparison} +% \changes{v2.1}{2007/01/08}{altered function to use \texttt{strlenstore}} % % \begin{macrocode} \newcommand{\ifstrleneq}[4]{% -\strchar{#1}{0}% -\ifthenelse{ \value{COOL@strpointer} = #2 }% +\strlenstore{#1}{COOL@strlen}% +\ifthenelse{ \value{COOL@strlen} = #2 }% {% #3% }% diff --git a/Master/texmf-dist/source/latex/coolstr/coolstr.ins b/Master/texmf-dist/source/latex/coolstr/coolstr.ins index 11e7781626e..5ee160edfdd 100644 --- a/Master/texmf-dist/source/latex/coolstr/coolstr.ins +++ b/Master/texmf-dist/source/latex/coolstr/coolstr.ins @@ -1,40 +1,40 @@ -%% -%% Copyright (C) 2005 by nsetzer -%% -%% This file may be distributed and/or modified under the -%% conditions of the Limited General Product License -%% - -\input docstrip.tex - -\keepsilent - -\usedir{tex/latex/coolstr} - -\preamble - -This is a generated file - -This file may be distributed and/or modified under the -conditions of the Limited General Product License - -\endpreamble - - -\generate{\file{coolstr.sty}{\from{coolstr.dtx}{package}}} - -\obeyspaces -\Msg{****************************************************} -\Msg{* *} -\Msg{* To finish the installation you have to move the *} -\Msg{* following file into a directory searched by TeX: *} -\Msg{* *} -\Msg{* coolstr.sty *} -\Msg{* *} -\Msg{* To produce the documentation run the file *} -\Msg{* coolstr.dtx through LaTeX. *} -\Msg{* *} -\Msg{* *} -\Msg{****************************************************} - +%% +%% Copyright (C) 2005 by nsetzer +%% +%% This file may be distributed and/or modified under the +%% conditions of the Limited General Product License +%% + +\input docstrip.tex + +\keepsilent + +\usedir{tex/latex/coolstr} + +\preamble + +This is a generated file + +This file may be distributed and/or modified under the +conditions of the Limited General Product License + +\endpreamble + + +\generate{\file{coolstr.sty}{\from{coolstr.dtx}{package}}} + +\obeyspaces +\Msg{****************************************************} +\Msg{* *} +\Msg{* To finish the installation you have to move the *} +\Msg{* following file into a directory searched by TeX: *} +\Msg{* *} +\Msg{* coolstr.sty *} +\Msg{* *} +\Msg{* To produce the documentation run the file *} +\Msg{* coolstr.dtx through LaTeX. *} +\Msg{* *} +\Msg{* *} +\Msg{****************************************************} + \endbatchfile \ No newline at end of file -- cgit v1.2.3