PluginProbe
Plugin Detective – Troubleshooting Conflicts / 1.2.35
Plugin Detective – Troubleshooting Conflicts v1.2.35
1.2.35 1.2.33 1.2.32 1.2.31 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2 1.2.1 1.2.10 1.2.12 1.2.13 1.2.14 1.2.16 1.2.19 1.2.20 1.2.22 1.2.23 1.2.24 All 54 releases
← All changes | troubleshoot/includes/class-string.php +706 -706 1.1.31.2.35 View file →
@@ -1,706 +1,706 @@
1 -<?php
2 -/**
3 - * Troubleshoot Config.
4 - *
5 - * @since 0.0.0
6 - * @package Troubleshoot
7 - */
8 -
9 -/**
10 - * Troubleshoot Config.
11 - *
12 - * @since 0.0.0
13 - */
14 -class PDT_String {
15 - // holds the value of the PDT_String object
16 - private $value;
17 -
18 - /*
19 - * Constructor
20 - *
21 - * The constructor sets the value of the PDT_String.
22 - *
23 - * @access public
24 - * @param string
25 - * @return void
26 - */
27 -
28 - public function __construct($value = '') {
29 -
30 - $this->value = (string) $value;
31 -
32 - }
33 -
34 - public function get_string() {
35 - return (string) $this->value;
36 - }
37 -
38 - /*
39 - * Returns the character at the specified index.
40 - *
41 - * @access public
42 - * @param int
43 - * @return char
44 - */
45 -
46 - public function charAt($index) {
47 -
48 - if (abs($index) >= $this->length()) {
49 - throw new Exception('Index out of bounds');
50 - }
51 -
52 - return substr($this->value, $index, 1);
53 -
54 - }
55 -
56 - /*
57 - * Returns the ASCII value of the character at the specified index.
58 - *
59 - * @access public
60 - * @param int
61 - * @return int
62 - */
63 -
64 - public function charCodeAt($index) {
65 -
66 - if (abs($index) >= $this->length()) {
67 - throw new Exception('Index out of bounds');
68 - }
69 -
70 - return ord($this->charAt($index));
71 -
72 - }
73 -
74 - /*
75 - * Compares two PDT_Strings.
76 - *
77 - * @access public
78 - * @param string
79 - * @return int
80 - */
81 -
82 - public function compareTo($that) {
83 -
84 - if (!($that instanceof PDT_String)) {
85 - $that = new PDT_String($that);
86 - }
87 - return strcmp($this->value, $that->value);
88 -
89 - }
90 -
91 - /*
92 - * Compares two PDT_Strings, ignoring case differences.
93 - *
94 - * @access public
95 - * @param string
96 - * @return int
97 - */
98 -
99 - public function compareToIgnoreCase($that) {
100 -
101 - if (!($that instanceof PDT_String)) {
102 - $that = new PDT_String($that);
103 - }
104 - return strcmp($this->toLowerCase()->value, $that->toLowerCase()->value);
105 -
106 - }
107 -
108 - /*
109 - * Concatenates the given string(s) to the end of this PDT_String.
110 - *
111 - * @access public
112 - * @param string
113 - * @return PDT_String
114 - */
115 -
116 - public function concat() {
117 -
118 - $strs = func_get_args();
119 - $temp = array();
120 - foreach ($strs as $str) {
121 - if (!($str instanceof PDT_String)) {
122 - $str = new PDT_String($str);
123 - }
124 - $temp[] = $str->value;
125 - }
126 - return new PDT_String($this->value . implode('', $temp));
127 -
128 - }
129 -
130 - /*
131 - * Returns TRUE if, and only if, this PDT_String contains the given sequence.
132 - *
133 - * @access public
134 - * @param string
135 - * @return boolean
136 - */
137 -
138 - public function contains($sequence) {
139 -
140 - return $this->indexOf($sequence) >= 0 ? TRUE : FALSE;
141 -
142 - }
143 -
144 - /*
145 - * Tests if this PDT_String ends with the specified suffix.
146 - *
147 - * @access public
148 - * @param string
149 - * @return boolean
150 - */
151 -
152 - public function endsWith($suffix) {
153 -
154 - return preg_match('/' . preg_quote($suffix) . '$/', $this->value);
155 -
156 - }
157 -
158 - /*
159 - * Compares this PDT_String to another PDT_String.
160 - *
161 - * @access public
162 - * @param string
163 - * @return boolean
164 - */
165 -
166 - public function equals($that, $ignoreCase = FALSE) {
167 -
168 - if (!($that instanceof PDT_String)) {
169 - $that = new PDT_String($that);
170 - }
171 -
172 - $a = $this;
173 - $b = $that;
174 -
175 - if ($ignoreCase === TRUE) {
176 - $a = $a->toLowerCase();
177 - $b = $b->toLowerCase();
178 - }
179 -
180 - return $a->value === $b->value;
181 -
182 - }
183 -
184 - /*
185 - * Compares this PDT_String to another PDT_String, ignoring case differences.
186 - *
187 - * @access public
188 - * @param string
189 - * @return boolean
190 - */
191 -
192 - public function equalsIgnoreCase($that) {
193 -
194 - return $this->equals($that, TRUE);
195 -
196 - }
197 -
198 - /*
199 - * Returns a formatted PDT_String.
200 - *
201 - * @access public
202 - * @return PDT_String
203 - */
204 -
205 - public static function format($str) {
206 -
207 - $args = func_get_args();
208 - $argc = count($args);
209 -
210 - for ($i = 1; $i < $argc; $i++) {
211 - $str = preg_replace('/\%s/', $args[$i], $str, 1);
212 - }
213 -
214 - return new PDT_String($str);
215 -
216 - }
217 -
218 - /*
219 - * Generates a PDT_String from given ASCII values.
220 - *
221 - * @access public
222 - * @return
223 - */
224 -
225 - public static function fromCharCode() {
226 -
227 - $args = func_get_args();
228 - $str = new PDT_String();
229 - foreach ($args as $arg) {
230 - $str = $str->concat(chr($arg));
231 - }
232 - return new PDT_String($str->value);
233 -
234 - }
235 -
236 - /*
237 - * Returns a hash code for this PDT_String.
238 - *
239 - * @access public
240 - * @return int
241 - */
242 -
243 - public function hashCode() {
244 -
245 - $h = 0;
246 - for ($i = 0, $l = $this->length(); $i < $l; $i++) {
247 - $h = 31 * $h + ord($this->charAt($i));
248 - }
249 - return $h;
250 -
251 - }
252 -
253 - /*
254 - * Returns the index within this PDT_String of the first occurrence of the
255 - * specified substring, or -1 if the substring does not occur.
256 - *
257 - * @access public
258 - * @param string
259 - * @param int
260 - * @return int
261 - */
262 -
263 - public function indexOf($substring, $fromIndex = 0) {
264 - if ($fromIndex >= $this->length() || $fromIndex < 0) {
265 - trace( $substring . ' ' . $fromIndex . ' >= ' . $this->length() );
266 - throw new Exception('Index out of bounds');
267 - }
268 -
269 - $index = strpos($this->value, $substring, $fromIndex);
270 - return (is_int($index)) ? $index : -1;
271 -
272 - }
273 -
274 - /*
275 - * Returns TRUE if, and only if, length is 0.
276 - *
277 - * @access public
278 - * @return boolean
279 - */
280 -
281 - public function isEmpty() {
282 -
283 - return $this->length() === 0 ? TRUE : FALSE;
284 -
285 - }
286 -
287 - /*
288 - * Returns the index within this PDT_String of the last occurrence of the
289 - * specified substring, or -1 if the substring does not occur.
290 - *
291 - * @access public
292 - * @param string
293 - * @param int
294 - * @return int
295 - */
296 -
297 - public function lastIndexOf($substring, $fromIndex = 0) {
298 -
299 - if ($fromIndex >= $this->length() || $fromIndex < 0) {
300 - throw new Exception('Index out of bounds');
301 - }
302 -
303 - $index = strrpos($this->value, $substring, $fromIndex);
304 - return is_int($index) ? $index : -1;
305 -
306 - }
307 -
308 - /*
309 - * Returns the length of this PDT_String.
310 - *
311 - * @access public
312 - * @return int
313 - */
314 -
315 - public function length() {
316 -
317 - return strlen($this->value);
318 -
319 - }
320 -
321 - /*
322 - * Tells whether or not this PDT_String matches the given pattern.
323 - *
324 - * @access public
325 - * @param string
326 - * @return boolean
327 - */
328 -
329 - public function matches($pattern) {
330 -
331 - return preg_match($pattern, $this->value);
332 -
333 - }
334 -
335 - /*
336 - * Encloses this PDT_String in double quotes
337 - *
338 - * @access public
339 - * @return PDT_String
340 - */
341 -
342 - public function quote($single = FALSE) {
343 -
344 - $quote = $single === FALSE ? '"' : "'";
345 -
346 - return new PDT_String($quote . $this->value . $quote);
347 -
348 - }
349 -
350 - /*
351 - * Test if two PDT_String regions are equal.
352 - *
353 - * @access public
354 - * @param int
355 - * @param PDT_String
356 - * @param int
357 - * @param int
358 - * @param boolean
359 - * @return boolean
360 - */
361 -
362 - public function regionMatches($offsetA, $that, $offsetB, $length, $ignoreCase = FALSE) {
363 -
364 - if (!($that instanceof PDT_String)) {
365 - $that = new PDT_String($that);
366 - }
367 -
368 - $a = $this->substring($offsetA, $length);
369 - $b = $that->substring($offsetB, $length);
370 -
371 - if ($ignoreCase === TRUE) {
372 - $a = $a->toLowerCase();
373 - $b = $b->toLowerCase();
374 - }
375 -
376 - return $a->value === $b->value;
377 -
378 - }
379 -
380 - /*
381 - * Test if two PDT_String regions are equal, ignoring case.
382 - *
383 - * @access public
384 - * @param int
385 - * @param PDT_String
386 - * @param int
387 - * @param int
388 - * @return boolean
389 - */
390 -
391 - public function regionMatchesIgnoreCase($offsetA, $that, $offsetB, $length) {
392 -
393 - return $this->regionMatches($offsetA, $that, $offsetB, $length, TRUE);
394 -
395 - }
396 -
397 - /*
398 - * Returns a new PDT_String resulting from replacing all occurrences of old in
399 - * this string with new.
400 - *
401 - * @access public
402 - * @param mixed
403 - * @param mixed
404 - * @param int
405 - * @return PDT_String
406 - */
407 -
408 - public function replace($old, $new, $count = NULL) {
409 -
410 - if ($count !== NULL) {
411 - $temp = str_replace($old, $new, $this->value, $count);
412 - } else {
413 - $temp = str_replace($old, $new, $this->value);
414 - }
415 - return new PDT_String($temp);
416 -
417 - }
418 -
419 - /*
420 - * Replaces each substring of this PDT_String that matches the given pattern
421 - * with the given replacement.
422 - *
423 - * @access public
424 - * @param string
425 - * @param string
426 - * @return PDT_String
427 - */
428 -
429 - public function replaceAll($pattern, $replacement) {
430 -
431 - $temp = preg_replace($pattern, $replacement, $this->value);
432 - return new PDT_String($temp);
433 -
434 - }
435 -
436 - /*
437 - * Replaces the first substring of this PDT_String that matches the given
438 - * pattern with the given replacement.
439 - *
440 - * @access public
441 - * @param string
442 - * @param string
443 - * @return PDT_String
444 - */
445 -
446 - public function replaceFirst($pattern, $replacement) {
447 -
448 - $temp = preg_replace($pattern, $replacement, $this->value, 1);
449 - return new PDT_String($temp);
450 -
451 - }
452 -
453 - /*
454 - * Splits this string around matches of the given pattern.
455 - *
456 - * @access public
457 - * @param string
458 - * @param int
459 - * @return array
460 - */
461 -
462 - public function split($pattern, $limit = NULL) {
463 -
464 - return preg_split($pattern, $this->value, $limit);
465 -
466 - }
467 -
468 - /*
469 - * Tests if this PDT_String starts with the specified prefix.
470 - *
471 - * @access public
472 - * @param string
473 - * @return boolean
474 - */
475 -
476 - public function startsWith($prefix) {
477 - return ( strpos( $this->value, $prefix ) === 0 );
478 - }
479 -
480 - /*
481 - * Returns a new PDT_String that is a substring of this string.
482 - *
483 - * @access public
484 - * @param int
485 - * @param int
486 - * @return PDT_String
487 - */
488 -
489 - public function substring($start, $length = NULL) {
490 -
491 - if ($length !== NULL) {
492 - $temp = substr($this->value, $start, $length);
493 - } else {
494 - $temp = substr($this->value, $start);
495 - }
496 - return new PDT_String($temp);
497 -
498 - }
499 -
500 - /*
501 - * Converts this PDT_String to an array of characters.
502 - *
503 - * @access public
504 - * @return array
505 - */
506 -
507 - public function toCharArray() {
508 -
509 - $chars = array();
510 - for ($i = 0, $l = $this->length(); $i < $l; $i++) {
511 - $chars[] = $this->charAt($i);
512 - }
513 - return $chars;
514 -
515 - }
516 -
517 - /*
518 - * Converts all of the characters in this PDT_String to lower case.
519 - *
520 - * @access public
521 - * @return PDT_String
522 - */
523 -
524 - public function toLowerCase() {
525 -
526 - return new PDT_String(strtolower($this->value));
527 -
528 - }
529 -
530 - /*
531 - * Converts all of the characters in this PDT_String to upper case.
532 - *
533 - * @access public
534 - * @return PDT_String
535 - */
536 -
537 - public function toUpperCase() {
538 -
539 - return new PDT_String(strtoupper($this->value));
540 -
541 - }
542 -
543 - /*
544 - * Removes leading and trailing whitespace.
545 - *
546 - * @access public
547 - * @return PDT_String
548 - */
549 -
550 - public function trim() {
551 -
552 - $temp = preg_replace('/^\s+/', '', preg_replace('/\s+$/', '', $this->value));
553 - return new PDT_String($temp);
554 -
555 - }
556 -
557 - /*
558 - * Removes leading whitespace.
559 - *
560 - * @access public
561 - * @return PDT_String
562 - */
563 -
564 - public function ltrim() {
565 -
566 - $temp = preg_replace('/^\s+/', '', $this->value);
567 - return new PDT_String($temp);
568 -
569 - }
570 -
571 - /*
572 - * Removes trailing whitespace.
573 - *
574 - * @access public
575 - * @return PDT_String
576 - */
577 -
578 - public function rtrim() {
579 -
580 - $temp = preg_replace('/\s+$/', '', $this->value);
581 - return new PDT_String($temp);
582 -
583 - }
584 -
585 - /*
586 - * Returns the value of this PDT_String
587 - *
588 - * @access public
589 - * @return string
590 - */
591 -
592 - public function __toPDT_String() {
593 -
594 - return $this->value;
595 -
596 - }
597 -
598 - /*
599 - * Deletes the right most string from the found search string
600 - * starting from right to left, including the search string itself.
601 - *
602 - * @access public
603 - * @return string
604 - */
605 -
606 - public function delRightMost($sSearch) {
607 - $sSource = $this->value;
608 - if ($sSearch !== ''){
609 - for ($i = strlen($sSource); $i >= 0; $i = $i - 1) {
610 - $f = strpos($sSource, $sSearch, $i);
611 - if ($f !== FALSE) {
612 - return new PDT_String(substr($sSource,0, $f));
613 - break;
614 - }
615 - }
616 - }
617 - return new PDT_String($sSource);
618 - }
619 -
620 - /*
621 - * Deletes the left most string from the found search string
622 - * starting from left to right, including the search string itself.
623 - *
624 - * @access public
625 - * @return string
626 - */
627 -
628 - public function delLeftMost($sSearch) {
629 - $sSource = $this->value;
630 - if ($sSearch !== ''){
631 - for ($i = 0; $i < strlen($sSource); $i = $i + 1) {
632 - $f = strpos($sSource, $sSearch, $i);
633 - if ($f !== FALSE) {
634 - return new PDT_String(substr($sSource,$f + strlen($sSearch), strlen($sSource)));
635 - break;
636 - }
637 - }
638 - }
639 - return new PDT_String($sSource);
640 - }
641 -
642 - /*
643 - * Returns the right most string from the found search string
644 - * starting from right to left, excluding the search string itself.
645 - *
646 - * @access public
647 - * @return string
648 - */
649 -
650 - public function getRightMost($sSearch) {
651 - $sSource = $this->value;
652 - if ($sSearch !== ''){
653 - for ($i = strlen($sSource); $i >= 0; $i = $i - 1) {
654 - $f = strpos($sSource, $sSearch, $i);
655 - if ($f !== FALSE) {
656 - return new PDT_String(substr($sSource,$f + strlen($sSearch), strlen($sSource)));
657 - }
658 - }
659 - }
660 - return new PDT_String($sSource);
661 - }
662 -
663 - /*
664 - * Returns the left most string from the found search string
665 - * starting from left to right, excluding the search string itself.
666 - *
667 - * @access public
668 - * @return string
669 - */
670 -
671 - public function getLeftMost($sSearch) {
672 - $sSource = $this->value;
673 - if ($sSearch !== ''){
674 - for ($i = 0; $i < strlen($sSource); $i = $i + 1) {
675 - $f = strpos($sSource, $sSearch, $i);
676 - if ($f !== FALSE) {
677 - return new PDT_String(substr($sSource,0, $f));
678 - break;
679 - }
680 - }
681 - }
682 - return new PDT_String($sSource);
683 - }
684 -
685 - /*
686 - * Returns left most string by the given number of characters.
687 - *
688 - * @access public
689 - * @return string
690 - */
691 -
692 - public function left($chars){
693 - return new PDT_String(substr($this->value, 0, $chars));
694 - }
695 -
696 - /*
697 - * Returns right most string by the given number of characters.
698 - *
699 - * @access public
700 - * @return string
701 - */
702 -
703 - public function right($chars){
704 - return new PDT_String(substr($this->value, ($chars*-1)));
705 - }
706 -}
1 +<?php
2 +/**
3 + * Troubleshoot Config.
4 + *
5 + * @since 0.0.0
6 + * @package Troubleshoot
7 + */
8 +
9 +/**
10 + * Troubleshoot Config.
11 + *
12 + * @since 0.0.0
13 + */
14 +class PDT_String {
15 + // holds the value of the PDT_String object
16 + private $value;
17 +
18 + /*
19 + * Constructor
20 + *
21 + * The constructor sets the value of the PDT_String.
22 + *
23 + * @access public
24 + * @param string
25 + * @return void
26 + */
27 +
28 + public function __construct($value = '') {
29 +
30 + $this->value = (string) $value;
31 +
32 + }
33 +
34 + public function get_string() {
35 + return (string) $this->value;
36 + }
37 +
38 + /*
39 + * Returns the character at the specified index.
40 + *
41 + * @access public
42 + * @param int
43 + * @return char
44 + */
45 +
46 + public function charAt($index) {
47 +
48 + if (abs($index) >= $this->length()) {
49 + throw new Exception('Index out of bounds');
50 + }
51 +
52 + return substr($this->value, $index, 1);
53 +
54 + }
55 +
56 + /*
57 + * Returns the ASCII value of the character at the specified index.
58 + *
59 + * @access public
60 + * @param int
61 + * @return int
62 + */
63 +
64 + public function charCodeAt($index) {
65 +
66 + if (abs($index) >= $this->length()) {
67 + throw new Exception('Index out of bounds');
68 + }
69 +
70 + return ord($this->charAt($index));
71 +
72 + }
73 +
74 + /*
75 + * Compares two PDT_Strings.
76 + *
77 + * @access public
78 + * @param string
79 + * @return int
80 + */
81 +
82 + public function compareTo($that) {
83 +
84 + if (!($that instanceof PDT_String)) {
85 + $that = new PDT_String($that);
86 + }
87 + return strcmp($this->value, $that->value);
88 +
89 + }
90 +
91 + /*
92 + * Compares two PDT_Strings, ignoring case differences.
93 + *
94 + * @access public
95 + * @param string
96 + * @return int
97 + */
98 +
99 + public function compareToIgnoreCase($that) {
100 +
101 + if (!($that instanceof PDT_String)) {
102 + $that = new PDT_String($that);
103 + }
104 + return strcmp($this->toLowerCase()->value, $that->toLowerCase()->value);
105 +
106 + }
107 +
108 + /*
109 + * Concatenates the given string(s) to the end of this PDT_String.
110 + *
111 + * @access public
112 + * @param string
113 + * @return PDT_String
114 + */
115 +
116 + public function concat() {
117 +
118 + $strs = func_get_args();
119 + $temp = array();
120 + foreach ($strs as $str) {
121 + if (!($str instanceof PDT_String)) {
122 + $str = new PDT_String($str);
123 + }
124 + $temp[] = $str->value;
125 + }
126 + return new PDT_String($this->value . implode('', $temp));
127 +
128 + }
129 +
130 + /*
131 + * Returns TRUE if, and only if, this PDT_String contains the given sequence.
132 + *
133 + * @access public
134 + * @param string
135 + * @return boolean
136 + */
137 +
138 + public function contains($sequence) {
139 +
140 + return $this->indexOf($sequence) >= 0 ? TRUE : FALSE;
141 +
142 + }
143 +
144 + /*
145 + * Tests if this PDT_String ends with the specified suffix.
146 + *
147 + * @access public
148 + * @param string
149 + * @return boolean
150 + */
151 +
152 + public function endsWith($suffix) {
153 +
154 + return preg_match('/' . preg_quote($suffix) . '$/', $this->value);
155 +
156 + }
157 +
158 + /*
159 + * Compares this PDT_String to another PDT_String.
160 + *
161 + * @access public
162 + * @param string
163 + * @return boolean
164 + */
165 +
166 + public function equals($that, $ignoreCase = FALSE) {
167 +
168 + if (!($that instanceof PDT_String)) {
169 + $that = new PDT_String($that);
170 + }
171 +
172 + $a = $this;
173 + $b = $that;
174 +
175 + if ($ignoreCase === TRUE) {
176 + $a = $a->toLowerCase();
177 + $b = $b->toLowerCase();
178 + }
179 +
180 + return $a->value === $b->value;
181 +
182 + }
183 +
184 + /*
185 + * Compares this PDT_String to another PDT_String, ignoring case differences.
186 + *
187 + * @access public
188 + * @param string
189 + * @return boolean
190 + */
191 +
192 + public function equalsIgnoreCase($that) {
193 +
194 + return $this->equals($that, TRUE);
195 +
196 + }
197 +
198 + /*
199 + * Returns a formatted PDT_String.
200 + *
201 + * @access public
202 + * @return PDT_String
203 + */
204 +
205 + public static function format($str) {
206 +
207 + $args = func_get_args();
208 + $argc = count($args);
209 +
210 + for ($i = 1; $i < $argc; $i++) {
211 + $str = preg_replace('/\%s/', $args[$i], $str, 1);
212 + }
213 +
214 + return new PDT_String($str);
215 +
216 + }
217 +
218 + /*
219 + * Generates a PDT_String from given ASCII values.
220 + *
221 + * @access public
222 + * @return
223 + */
224 +
225 + public static function fromCharCode() {
226 +
227 + $args = func_get_args();
228 + $str = new PDT_String();
229 + foreach ($args as $arg) {
230 + $str = $str->concat(chr($arg));
231 + }
232 + return new PDT_String($str->value);
233 +
234 + }
235 +
236 + /*
237 + * Returns a hash code for this PDT_String.
238 + *
239 + * @access public
240 + * @return int
241 + */
242 +
243 + public function hashCode() {
244 +
245 + $h = 0;
246 + for ($i = 0, $l = $this->length(); $i < $l; $i++) {
247 + $h = 31 * $h + ord($this->charAt($i));
248 + }
249 + return $h;
250 +
251 + }
252 +
253 + /*
254 + * Returns the index within this PDT_String of the first occurrence of the
255 + * specified substring, or -1 if the substring does not occur.
256 + *
257 + * @access public
258 + * @param string
259 + * @param int
260 + * @return int
261 + */
262 +
263 + public function indexOf($substring, $fromIndex = 0) {
264 + if ($fromIndex >= $this->length() || $fromIndex < 0) {
265 + trace( $substring . ' ' . $fromIndex . ' >= ' . $this->length() );
266 + throw new Exception('Index out of bounds');
267 + }
268 +
269 + $index = strpos($this->value, $substring, $fromIndex);
270 + return (is_int($index)) ? $index : -1;
271 +
272 + }
273 +
274 + /*
275 + * Returns TRUE if, and only if, length is 0.
276 + *
277 + * @access public
278 + * @return boolean
279 + */
280 +
281 + public function isEmpty() {
282 +
283 + return $this->length() === 0 ? TRUE : FALSE;
284 +
285 + }
286 +
287 + /*
288 + * Returns the index within this PDT_String of the last occurrence of the
289 + * specified substring, or -1 if the substring does not occur.
290 + *
291 + * @access public
292 + * @param string
293 + * @param int
294 + * @return int
295 + */
296 +
297 + public function lastIndexOf($substring, $fromIndex = 0) {
298 +
299 + if ($fromIndex >= $this->length() || $fromIndex < 0) {
300 + throw new Exception('Index out of bounds');
301 + }
302 +
303 + $index = strrpos($this->value, $substring, $fromIndex);
304 + return is_int($index) ? $index : -1;
305 +
306 + }
307 +
308 + /*
309 + * Returns the length of this PDT_String.
310 + *
311 + * @access public
312 + * @return int
313 + */
314 +
315 + public function length() {
316 +
317 + return strlen($this->value);
318 +
319 + }
320 +
321 + /*
322 + * Tells whether or not this PDT_String matches the given pattern.
323 + *
324 + * @access public
325 + * @param string
326 + * @return boolean
327 + */
328 +
329 + public function matches($pattern) {
330 +
331 + return preg_match($pattern, $this->value);
332 +
333 + }
334 +
335 + /*
336 + * Encloses this PDT_String in double quotes
337 + *
338 + * @access public
339 + * @return PDT_String
340 + */
341 +
342 + public function quote($single = FALSE) {
343 +
344 + $quote = $single === FALSE ? '"' : "'";
345 +
346 + return new PDT_String($quote . $this->value . $quote);
347 +
348 + }
349 +
350 + /*
351 + * Test if two PDT_String regions are equal.
352 + *
353 + * @access public
354 + * @param int
355 + * @param PDT_String
356 + * @param int
357 + * @param int
358 + * @param boolean
359 + * @return boolean
360 + */
361 +
362 + public function regionMatches($offsetA, $that, $offsetB, $length, $ignoreCase = FALSE) {
363 +
364 + if (!($that instanceof PDT_String)) {
365 + $that = new PDT_String($that);
366 + }
367 +
368 + $a = $this->substring($offsetA, $length);
369 + $b = $that->substring($offsetB, $length);
370 +
371 + if ($ignoreCase === TRUE) {
372 + $a = $a->toLowerCase();
373 + $b = $b->toLowerCase();
374 + }
375 +
376 + return $a->value === $b->value;
377 +
378 + }
379 +
380 + /*
381 + * Test if two PDT_String regions are equal, ignoring case.
382 + *
383 + * @access public
384 + * @param int
385 + * @param PDT_String
386 + * @param int
387 + * @param int
388 + * @return boolean
389 + */
390 +
391 + public function regionMatchesIgnoreCase($offsetA, $that, $offsetB, $length) {
392 +
393 + return $this->regionMatches($offsetA, $that, $offsetB, $length, TRUE);
394 +
395 + }
396 +
397 + /*
398 + * Returns a new PDT_String resulting from replacing all occurrences of old in
399 + * this string with new.
400 + *
401 + * @access public
402 + * @param mixed
403 + * @param mixed
404 + * @param int
405 + * @return PDT_String
406 + */
407 +
408 + public function replace($old, $new, $count = NULL) {
409 +
410 + if ($count !== NULL) {
411 + $temp = str_replace($old, $new, $this->value, $count);
412 + } else {
413 + $temp = str_replace($old, $new, $this->value);
414 + }
415 + return new PDT_String($temp);
416 +
417 + }
418 +
419 + /*
420 + * Replaces each substring of this PDT_String that matches the given pattern
421 + * with the given replacement.
422 + *
423 + * @access public
424 + * @param string
425 + * @param string
426 + * @return PDT_String
427 + */
428 +
429 + public function replaceAll($pattern, $replacement) {
430 +
431 + $temp = preg_replace($pattern, $replacement, $this->value);
432 + return new PDT_String($temp);
433 +
434 + }
435 +
436 + /*
437 + * Replaces the first substring of this PDT_String that matches the given
438 + * pattern with the given replacement.
439 + *
440 + * @access public
441 + * @param string
442 + * @param string
443 + * @return PDT_String
444 + */
445 +
446 + public function replaceFirst($pattern, $replacement) {
447 +
448 + $temp = preg_replace($pattern, $replacement, $this->value, 1);
449 + return new PDT_String($temp);
450 +
451 + }
452 +
453 + /*
454 + * Splits this string around matches of the given pattern.
455 + *
456 + * @access public
457 + * @param string
458 + * @param int
459 + * @return array
460 + */
461 +
462 + public function split($pattern, $limit = NULL) {
463 +
464 + return preg_split($pattern, $this->value, $limit);
465 +
466 + }
467 +
468 + /*
469 + * Tests if this PDT_String starts with the specified prefix.
470 + *
471 + * @access public
472 + * @param string
473 + * @return boolean
474 + */
475 +
476 + public function startsWith($prefix) {
477 + return ( strpos( $this->value, $prefix ) === 0 );
478 + }
479 +
480 + /*
481 + * Returns a new PDT_String that is a substring of this string.
482 + *
483 + * @access public
484 + * @param int
485 + * @param int
486 + * @return PDT_String
487 + */
488 +
489 + public function substring($start, $length = NULL) {
490 +
491 + if ($length !== NULL) {
492 + $temp = substr($this->value, $start, $length);
493 + } else {
494 + $temp = substr($this->value, $start);
495 + }
496 + return new PDT_String($temp);
497 +
498 + }
499 +
500 + /*
501 + * Converts this PDT_String to an array of characters.
502 + *
503 + * @access public
504 + * @return array
505 + */
506 +
507 + public function toCharArray() {
508 +
509 + $chars = array();
510 + for ($i = 0, $l = $this->length(); $i < $l; $i++) {
511 + $chars[] = $this->charAt($i);
512 + }
513 + return $chars;
514 +
515 + }
516 +
517 + /*
518 + * Converts all of the characters in this PDT_String to lower case.
519 + *
520 + * @access public
521 + * @return PDT_String
522 + */
523 +
524 + public function toLowerCase() {
525 +
526 + return new PDT_String(strtolower($this->value));
527 +
528 + }
529 +
530 + /*
531 + * Converts all of the characters in this PDT_String to upper case.
532 + *
533 + * @access public
534 + * @return PDT_String
535 + */
536 +
537 + public function toUpperCase() {
538 +
539 + return new PDT_String(strtoupper($this->value));
540 +
541 + }
542 +
543 + /*
544 + * Removes leading and trailing whitespace.
545 + *
546 + * @access public
547 + * @return PDT_String
548 + */
549 +
550 + public function trim() {
551 +
552 + $temp = preg_replace('/^\s+/', '', preg_replace('/\s+$/', '', $this->value));
553 + return new PDT_String($temp);
554 +
555 + }
556 +
557 + /*
558 + * Removes leading whitespace.
559 + *
560 + * @access public
561 + * @return PDT_String
562 + */
563 +
564 + public function ltrim() {
565 +
566 + $temp = preg_replace('/^\s+/', '', $this->value);
567 + return new PDT_String($temp);
568 +
569 + }
570 +
571 + /*
572 + * Removes trailing whitespace.
573 + *
574 + * @access public
575 + * @return PDT_String
576 + */
577 +
578 + public function rtrim() {
579 +
580 + $temp = preg_replace('/\s+$/', '', $this->value);
581 + return new PDT_String($temp);
582 +
583 + }
584 +
585 + /*
586 + * Returns the value of this PDT_String
587 + *
588 + * @access public
589 + * @return string
590 + */
591 +
592 + public function __toPDT_String() {
593 +
594 + return $this->value;
595 +
596 + }
597 +
598 + /*
599 + * Deletes the right most string from the found search string
600 + * starting from right to left, including the search string itself.
601 + *
602 + * @access public
603 + * @return string
604 + */
605 +
606 + public function delRightMost($sSearch) {
607 + $sSource = $this->value;
608 + if ($sSearch !== ''){
609 + for ($i = strlen($sSource); $i >= 0; $i = $i - 1) {
610 + $f = strpos($sSource, $sSearch, $i);
611 + if ($f !== FALSE) {
612 + return new PDT_String(substr($sSource,0, $f));
613 + break;
614 + }
615 + }
616 + }
617 + return new PDT_String($sSource);
618 + }
619 +
620 + /*
621 + * Deletes the left most string from the found search string
622 + * starting from left to right, including the search string itself.
623 + *
624 + * @access public
625 + * @return string
626 + */
627 +
628 + public function delLeftMost($sSearch) {
629 + $sSource = $this->value;
630 + if ($sSearch !== ''){
631 + for ($i = 0; $i < strlen($sSource); $i = $i + 1) {
632 + $f = strpos($sSource, $sSearch, $i);
633 + if ($f !== FALSE) {
634 + return new PDT_String(substr($sSource,$f + strlen($sSearch), strlen($sSource)));
635 + break;
636 + }
637 + }
638 + }
639 + return new PDT_String($sSource);
640 + }
641 +
642 + /*
643 + * Returns the right most string from the found search string
644 + * starting from right to left, excluding the search string itself.
645 + *
646 + * @access public
647 + * @return string
648 + */
649 +
650 + public function getRightMost($sSearch) {
651 + $sSource = $this->value;
652 + if ($sSearch !== ''){
653 + for ($i = strlen($sSource); $i >= 0; $i = $i - 1) {
654 + $f = strpos($sSource, $sSearch, $i);
655 + if ($f !== FALSE) {
656 + return new PDT_String(substr($sSource,$f + strlen($sSearch), strlen($sSource)));
657 + }
658 + }
659 + }
660 + return new PDT_String($sSource);
661 + }
662 +
663 + /*
664 + * Returns the left most string from the found search string
665 + * starting from left to right, excluding the search string itself.
666 + *
667 + * @access public
668 + * @return string
669 + */
670 +
671 + public function getLeftMost($sSearch) {
672 + $sSource = $this->value;
673 + if ($sSearch !== ''){
674 + for ($i = 0; $i < strlen($sSource); $i = $i + 1) {
675 + $f = strpos($sSource, $sSearch, $i);
676 + if ($f !== FALSE) {
677 + return new PDT_String(substr($sSource,0, $f));
678 + break;
679 + }
680 + }
681 + }
682 + return new PDT_String($sSource);
683 + }
684 +
685 + /*
686 + * Returns left most string by the given number of characters.
687 + *
688 + * @access public
689 + * @return string
690 + */
691 +
692 + public function left($chars){
693 + return new PDT_String(substr($this->value, 0, $chars));
694 + }
695 +
696 + /*
697 + * Returns right most string by the given number of characters.
698 + *
699 + * @access public
700 + * @return string
701 + */
702 +
703 + public function right($chars){
704 + return new PDT_String(substr($this->value, ($chars*-1)));
705 + }
706 +}