Skip to content

Commit

Permalink
filled in JavaString
Browse files Browse the repository at this point in the history
  • Loading branch information
duckpilot committed Jun 14, 2010
1 parent 76a29bd commit e9e992c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/ojox/javaScriptObject.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ let cast = Obj.magic

let equals a b = << $a$ === $b$ >>

let hashCode o = failwith "unimplemented" (* XXX Impl *)
let hashCode = Impl.getHashCode

let toString o = << $o$.toString ? $o$.toString() : "[JavaScriptObject]" >>
41 changes: 32 additions & 9 deletions src/ojox/javaString.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,36 @@

open Ocamljs.Inline

let charAt s index = failwith "unimplemented"
let contains s1 s2 = failwith "unimplemented"
let equalsIgnoreCase s1 s2 = failwith "unimplemented"
let charAt s index = << $s$.charCodeAt($index$) >>

let equalsIgnoreCase s1 s2 = <:rstmt<
if ($s2$ == null)
return false;
return ($s1$ == $s2$) || ($s1$.toLowerCase() == $s2$.toLowerCase());
>>

let fromCharCode ch = << String.fromCharCode ch >>
let indexOf s ?startIndex str = failwith "unimplemented"
let indexOf_char s ?startIndex str = failwith "unimplemented"
let length s = failwith "unimplemented"
let substring s ?endIndex startIndex = failwith "unimplemented"
let toLowerCase s = failwith "unimplemented"
let trim s = failwith "unimplemented"

let indexOf s ?startIndex str = << $s$.indexOf($str$, $Ocamljs.nullable_of_option startIndex$) >>

let contains s1 s2 = indexOf s1 s2 != -1

let length s = << $s$.length >>

let substring s ?endIndex beginIndex =
let len =
match endIndex with
| None -> length s - beginIndex
| Some endIndex -> endIndex - beginIndex in
<< $s$.substr($beginIndex$, $len$) >>

let toLowerCase s = << $s$.toLowerCase() >>

let trim s = <:rstmt<
if ($s$.length == 0 || ($s$[0] > '\u0020' && $s$[$s$.length-1] > '\u0020')) {
return $s$;
}
var r1 = $s$.replace(/^(\s*)/, '');
var r2 = r1.replace(/\s*$/, '');
return r2;
>>
1 change: 0 additions & 1 deletion src/ojox/javaString.mli
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ val contains : string -> string -> bool
val equalsIgnoreCase : string -> string -> bool
val fromCharCode : char -> string
val indexOf : string -> ?startIndex:int -> string -> int
val indexOf_char : string -> ?startIndex:int -> char -> int
val length : string -> int
val substring : string -> ?endIndex:int -> int -> string
val toLowerCase : string -> string
Expand Down
2 changes: 1 addition & 1 deletion src/ojox/uIObject.ml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ let getStylePrimaryName elem =
(* The primary style name is always the first token of the full CSS class
name. There can be no leading whitespace in the class name, so it's not
necessary to trim() it. *)
let spaceIdx = JavaString.indexOf_char fullClassName ' ' in
let spaceIdx = JavaString.indexOf fullClassName " " in
if spaceIdx >= 0
then JavaString.substring ~endIndex:spaceIdx fullClassName 0
else fullClassName
Expand Down

0 comments on commit e9e992c

Please sign in to comment.