From 392452ecf4283ae17030bc5c71095f3d230da768 Mon Sep 17 00:00:00 2001 From: Waldo Jaquith Date: Wed, 12 Jun 2013 14:55:57 -0400 Subject: [PATCH] Store a list of prefixes, in order This is a step towards solving issue #1, which requires stateful knowledge of the ordinal values of prefixes. --- subsection-identifier.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/subsection-identifier.php b/subsection-identifier.php index a4b31f1..6f4fbde 100644 --- a/subsection-identifier.php +++ b/subsection-identifier.php @@ -51,13 +51,17 @@ function parse() * parentheses or followed by a period and a space. We pair that with a list of all possible * characters that can appear within that range, which we use to verify the match. */ - $prefix_candidates = array ('/[A-Z]{1,2}\. /', - '/[0-9]{1,2}\. /', - '/[a-z]{1,2}\. /', - '/\([0-9]{1,2}\) /', - '/\([a-z]{1,2}\) /', - '/\((xvi[1,4})\) /'); - + $prefix_candidates = array ( + '/[0-9]{1,2}\. /' => range(1, 99), + '/\([0-9]{1,2}\) /' => range(1, 99), + '/[a-z]{1,2}\. /' => range('a', 'z'), + '/\([a-z]{1,2}\) /' => range('a', 'z'), + '/[A-Z]{1,2}\. /' => range('A', 'Z'), + '/\([A-Z]{1,2}\) /' => range('a', 'z'), + '/([xvi]{1,4})\. /' => array('i', 'ii', 'iii', 'iv', 'v', 'vi', 'vii', 'viii', 'ix', 'x', 'xi', 'xii', 'xiii', 'xiv', 'xv', 'xvi', 'xvii', 'xviii', 'xix', 'xx'), + '/\(([xvi]{1,4})\) /' => array('i', 'ii', 'iii', 'iv', 'v', 'vi', 'vii', 'viii', 'ix', 'x', 'xi', 'xii', 'xiii', 'xiv', 'xv', 'xvi', 'xvii', 'xviii', 'xix', 'xx') + ); + /* * Establish a blank prefix structure. We'll build this up and continually modify it to keep * track of our current complete section number as we iterate through the text.