Source

ocamlspot / name.ml

camlspotter fb1f10e 
































(***********************************************************************)
(*                                                                     *)
(*                            OCamlSpotter                             *)
(*                                                                     *)
(*                             Jun FURUSE                              *)
(*                                                                     *)
(*   Copyright 2008, 2009, 2010 Jun Furuse. All rights reserved.       *)
(*   This file is distributed under the terms of the GNU Library       *)
(*   General Public License, with the special exception on linking     *)
(*   described in file LICENSE.                                        *)
(*                                                                     *)
(***********************************************************************)

type t = string

let create name = function
  | -1 -> Printf.sprintf "%s__G" name
  | n -> Printf.sprintf "%s__%d" name n
;;

let parse s =
  try
    let pos = String.rindex s '_' in
    if pos = 0 then raise Not_found;
    if s.[pos-1] <> '_' then raise Not_found;
    let n = String.sub s 0 (pos-1) in
    let id =
      match String.sub s (pos+1) (String.length s - pos - 1) with
      | "G" -> -1
      | s -> int_of_string s
    in
    n, id
  with
  | _ -> raise Not_found
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.