File src/de/jandankert/jscriptbox/standard/internal/StringInstance.java
Last commit: Sun May 31 00:20:40 2026 +0200 Jan Dankert Fixing some javadoc errors.
1 2 3 4 package de.jandankert.jscriptbox.standard.internal; 5 6 7 import de.jandankert.jscriptbox.context.BaseScriptable; 8 import de.jandankert.jscriptbox.context.ContextPrimitive; 9 10 public class StringInstance extends BaseScriptable implements ContextPrimitive 11 { 12 private String value; 13 14 /** 15 * Number constructor. 16 * @param value Value. 17 */ 18 public StringInstance(String value) 19 { 20 /* 21 if ( value instanceof BaseScriptableObject ) 22 this->value = $value->__toString(); 23 24 elseif ( is_object( value ) ) 25 this->value = get_class($value); 26 27 elseif ( is_bool( $value ) ) 28 this->value = $value ? 'true' : 'false'; 29 else*/ 30 this.value = value; 31 } 32 33 public String toString() 34 { 35 return this.value; 36 } 37 38 39 /* 40 public function __invoke( $value ) 41 { 42 return new StringInstance( $value ); 43 } 44 */ 45 46 47 /* 48 public function split( $splitChar = null ) { 49 if ( $splitChar == '' ) 50 return str_split( $this->value ); 51 if ( $splitChar == null ) 52 return array( $this->value ); 53 54 return explode( $splitChar, $this->value ); 55 } 56 57 58 public function trim() { 59 return trim( $this->value); 60 } 61 public function trimEnd() { 62 return rtrim( $this->value); 63 64 } 65 public function trimStart() { 66 return ltrim( $this->value); 67 } 68 69 public function valueOf( $val ) { 70 return new StringInstance( $val ); 71 } 72 73 public function charAt( $pos ) { 74 return substr( $this->value,$pos,1 ); 75 } 76 77 public function concat( $str ) { 78 return $this->value.$str; 79 } 80 81 public function startsWith($str) { 82 return substr( $this->value, 0,strlen($str) ); 83 } 84 85 public function endsWith($str ) { 86 return substr( $this->value,strlen($str)*-1,strlen($str)) == $str; 87 } 88 89 public function indexOf( $search ) { 90 return strpos( $this->value, $search ); 91 } 92 93 public function lastIndexOf( $search) { 94 return strrpos( $this->value, $search ); 95 } 96 97 public function padStart($length,$pad=null) { 98 $this->value = str_pad( $this->value,$length, STR_PAD_LEFT); 99 } 100 101 public function padEnd( $length,$pad=null) { 102 $this->value = str_pad( $this->value,$length, STR_PAD_RIGHT); 103 } 104 105 public function repeat( $count) { 106 return str_repeat( $this->value,$count); 107 } 108 109 public function replace( $search,$replaceWith ) { 110 $c = 1; 111 return str_replace( $search,$replaceWith,$this->value,$c ); 112 } 113 114 public function replaceAll( $search,$replaceWith ) { 115 return str_replace( $search,$replaceWith,$this->value ); 116 } 117 118 public function slice( $begin,$end=null) { 119 return array_slice( $this->value,$begin,$end-$begin); 120 } 121 122 public function substring( $start,$end) { 123 return substr( $this->value, $start,$end-$start+1 ); 124 } 125 126 public function toLowerCase() { 127 return strtolower($this->value); 128 } 129 130 public function toUpperCase() { 131 return strtoupper($this->value); 132 } 133 134 // public function length() { 135 // return strlen($this->value); 136 // } 137 */ 138 }
Downloadsrc/de/jandankert/jscriptbox/standard/internal/StringInstance.java
History Sun, 31 May 2026 00:20:40 +0200 Jan Dankert Fixing some javadoc errors. Sat, 30 May 2026 23:22:58 +0200 Jan Dankert Refactoring package openrat->jandankert because the maven artefact is in namespace de.jandankert