-
- /* $Id$ */
-
- if (defined('strings_php'))
- return;
- define('strings_php', true);
-
-
- //*************************************************************************
- // Count the number of occurances of $needle are in $haystack.
- // $needle can be a character or string, and need not occur in $haystack
- //*************************************************************************
- function countCharInString($haystack, $needle) {
- if ($needle == '') return 0;
- return count(explode($needle, $haystack));
- }
-
- //*************************************************************************
- // Read from the back of $haystack until $needle is found, or the begining
- // of the $haystack is reached. $needle is a single character
- //*************************************************************************
- function readShortMailboxName($haystack, $needle) {
- if ($needle == '') return $haystack;
- $parts = explode($needle, $haystack);
- $elem = array_pop($parts);
- while ($elem == '' && count($parts))
- {
- $elem = array_pop($parts);
- }
- return $elem;
- }
-
- //*************************************************************************
- // Read from the back of $haystack until $needle is found, or the begining
- // of the $haystack is reached. $needle is a single character
- //*************************************************************************
- function readMailboxParent($haystack, $needle) {
- if ($needle == '') return '';
- $parts = explode($needle, $haystack);
- $elem = array_pop($parts);
- while ($elem == '' && count($parts))
- {
- $elem = array_pop($parts);
- }
- return join($needle, $parts);
- }
-
- // Searches for the next position in a string minus white space
- function next_pos_minus_white ($haystack, $pos) {
- while (substr($haystack, $pos, 1) == ' ' ||
- substr($haystack, $pos, 1) == "\t" ||
- substr($haystack, $pos, 1) == "\n" ||
- substr($haystack, $pos, 1) == "\r") {
- if ($pos >= strlen($haystack))
- return -1;
- $pos++;
- }
- return $pos;
- }
-
- // Wraps text at $wrap characters
- // Has a problem with special HTML characters, so call this before
- // you do character translation.
- // Specifically, ' comes up as 5 characters instead of 1.
- // This should not add newlines to the end of lines.
- function sqWordWrap(&$line, $wrap) {
- ereg("^([\t >]*)([^\t >].*)?$", $line, $regs);
- $beginning_spaces = $regs[1];
- if (isset($regs[2])) {
- $words = explode(' ', $regs[2]);
- } else {
- $words = "";
- }
-
- $i = 0;
- $line = $beginning_spaces;
-
- while ($i < count($words)) {
- // Force one word to be on a line (minimum)
- $line .= $words[$i];
- $line_len = strlen($beginning_spaces) + strlen($words[$i]) + 2;
- if (isset($words[$i + 1]))
- $line_len += strlen($words[$i + 1]);
- $i ++;
-
- // Add more words (as long as they fit)
- while ($line_len < $wrap && $i < count($words)) {
+
+/**
+ * strings.php
+ *
+ * Copyright (c) 1999-2002 The SquirrelMail Project Team
+ * Licensed under the GNU GPL. For full terms see the file COPYING.
+ *
+ * This code provides various string manipulation functions that are
+ * used by the rest of the Squirrelmail code.
+ *
+ * $Id$
+ */
+
+/*****************************************************************/
+/*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/
+/*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/
+/*** + Base level indent should begin at left margin, as ***/
+/*** the comment and $version stuff below. ***/
+/*** + All identation should consist of four space blocks ***/
+/*** + Tab characters are evil. ***/
+/*** + all comments should use "slash-star ... star-slash" ***/
+/*** style -- no pound characters, no slash-slash style ***/
+/*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/
+/*** ALWAYS USE { AND } CHARACTERS!!! ***/
+/*** + Please use ' instead of ", when possible. Note " ***/
+/*** should always be used in _( ) function calls. ***/
+/*** Thank you for your help making the SM code more readable. ***/
+/*****************************************************************/
+
+/**
+ * SquirrelMail version number -- DO NOT CHANGE
+ */
+global $version;
+$version = '1.2.5 [cvs]';
+
+/**
+ * If $haystack is a full mailbox name and $needle is the mailbox
+ * separator character, returns the last part of the mailbox name.
+ */
+function readShortMailboxName($haystack, $needle) {
+ if ($needle == '') {
+ return $haystack;
+ }
+ $parts = explode($needle, $haystack);
+ $elem = array_pop($parts);
+ while ($elem == '' && count($parts)) {
+ $elem = array_pop($parts);
+ }
+ return $elem;
+}
+
+/**
+ * If $haystack is a full mailbox name, and $needle is the mailbox
+ * separator character, returns the second last part of the full
+ * mailbox name (i.e. the mailbox's parent mailbox)
+ */
+function readMailboxParent($haystack, $needle) {
+ if ($needle == '') return '';
+ $parts = explode($needle, $haystack);
+ $elem = array_pop($parts);
+ while ($elem == '' && count($parts)) {
+ $elem = array_pop($parts);
+ }
+ return join($needle, $parts);
+}
+
+/**
+ * Returns the index of the first chunk of string $haystack that
+ * starts with non-white-space character, starting at position $pos.
+ * If there is no such chunk, returns -1.
+ */
+function next_pos_minus_white ($haystack, $pos) {
+ $len = strlen($haystack);
+ while ($pos < $len) {
+ /* Get the next character. */
+ $c = substr($haystack, $pos, 1);
+
+ /* Check the next character. */
+ if (($c != ' ') && ($c != "\t") && ($c != "\n") && ($c != "\r")) {
+ return $pos;
+ }
+
+ /* Increment position in string. */
+ ++$pos;
+ }
+ return -1;
+}
+
+/**
+ * Wraps text at $wrap characters
+ *
+ * Has a problem with special HTML characters, so call this before
+ * you do character translation.
+ *
+ * Specifically, ' comes up as 5 characters instead of 1.
+ * This should not add newlines to the end of lines.
+ */
+function sqWordWrap(&$line, $wrap) {
+ ereg("^([\t >]*)([^\t >].*)?$", $line, $regs);
+ $beginning_spaces = $regs[1];
+ if (isset($regs[2])) {
+ $words = explode(' ', $regs[2]);
+ } else {
+ $words = "";
+ }
+
+ $i = 0;
+ $line = $beginning_spaces;
+
+ while ($i < count($words)) {
+ // Force one word to be on a line (minimum)
+ $line .= $words[$i];
+ $line_len = strlen($beginning_spaces) + strlen($words[$i]) + 2;
+ if (isset($words[$i + 1]))
+ $line_len += strlen($words[$i + 1]);
+ $i ++;
+
+ // Add more words (as long as they fit)
+ while ($line_len < $wrap && $i < count($words)) {