Package erjang

Examples of erjang.EString


    RPC.wait_for_erjang_started(60*1000L);   

    //
    // Call erlang:display( ["Hello, Joe!~n", []] )
    //
    EString hello_str = EString.fromString("Hello, Joe!~n");
    ESeq format_args = EList.make( hello_str, ERT.NIL );    
    RPC.call(am_erlang, am_display, (EObject)format_args );

   
    RPC.call(am_io, am_format, hello_str, ERT.NIL );
View Full Code Here


      ESmall val = value.testSmall();
      if (val != null) {
        exitCode = val.value;
      }
     
      EString str = value.testString();
      if (str != null) {
        message = str.stringValue();
      }
    }
   
    /*
    // TODO: create crash file
View Full Code Here

      return new ESmall(ERT.threadPoolSize());
     
    } else if (type == am_os_type) {
      String os = System.getProperty("os.name");
      if (os.startsWith("Windows")) {
        return ETuple.make(am_win32, new EString(os));
      } else {
        return ETuple.make(am_unix, new EString(os));
      }

    } else if (type == am_threads) {
      return ERT.TRUE;
     
    } else if (type == am_version) {
      String erts_version = ERT.runtime_info.erts_version;
      // remove prefix
      String prefix = "erts-";
      if (erts_version.startsWith(prefix)) {
        erts_version = erts_version.substring(prefix.length());
      }
      return EString.fromString(erts_version);
     
    } else if (type == am_otp_release) {
      return new EString(ERT.runtime_info.otp_version);
    } else if (type == am_logical_processors) {
      // TODO: be smarter somehow
      return ERT.box(Runtime.getRuntime().availableProcessors());
     
    } else if (type == am_global_heaps_size) {
      return ERT.box(Runtime.getRuntime().totalMemory());
     
    } else if (type == am_process_count) {
      return ERT.box(EProc.process_count());
     
    } else if (type == am_system_architecture) {
      return new EString(Main.SYSTEM_ARCHITECTURE);
     
    } else if (type == am_driver_version) {
      // TODO: be smarter somehow
      return new EString(Main.DRIVER_VERSION);
     
    } else if (type == am_wordsize) {
      return new ESmall(4);
      
    } else if (type == am_debug_compiled || type == am_lock_checking) {
       throw ERT.badarg(type);
      
    } else if (type == am_hipe_architecture) {
      return am_undefined;
     
    } else if (type == am_build_type) {
      return EAtom.intern("opt");
     
    } else if (type == am_system_version) {
      return new EString("Erjang ["+ ERT.runtime_info.erts_version+"]");
     
    } else if ((tup=ETuple2.cast(type)) != null) {
     
      if (tup.elem1 == am_allocator) {
        if (tup.elem2 == am_ets_alloc) {
View Full Code Here

        EBinary bin;
        if ((bin = io_or_char_list.testBinary()) != null) {
          return EString.make(bin).stringValue();
        }
       
        EString str;
        if ((str = io_or_char_list.testString()) != null) {
          return str.stringValue();
        }
       
        List<ByteBuffer> bb = new ArrayList<ByteBuffer>();
        if (io_or_char_list.collectIOList(bb)) {
          StringWriter sw = new StringWriter();
View Full Code Here

  static Pattern float_pattern = Pattern.compile("^((-|\\+)?\\d*\\.\\d+([eE](-|\\+)?\\d+)?).*");
 
  @BIF
  public static ETuple2 to_integer(EObject val)
  {
    EString v = val.testString();
    if (v == null) throw ERT.badarg(val);
   
    String s = v.stringValue();
    Matcher m = int_pattern.matcher(s);
    if (m.matches()) {
      String ss = m.group(1);
      EInteger intval = ERT.box_parse(ss);
      ESeq rest;
      if (ss.length() == s.length()) {
        rest = ERT.NIL;
      } else {
        rest = new EString(s.substring(ss.length()));
      }
      return new ETuple2(intval, rest);     
    } else {
      return new ETuple2(am_error, am_no_integer);
    }
View Full Code Here

  }
 
  @BIF
  public static ETuple2 to_float(EObject val)
  {
    EString v = val.testString();
    if (v == null) throw ERT.badarg(val);
   
    String s = v.stringValue();
    Matcher m = float_pattern.matcher(s);
    if (m.matches()) {
      String ss = m.group(1);
      EDouble floatval = ERT.box( Double.parseDouble(ss) );
      ESeq rest;
      if (ss.length() == s.length()) {
        rest = ERT.NIL;
      } else {
        rest = new EString(s.substring(ss.length()));
      }
      return new ETuple2(floatval, rest);     
    } else {
      return new ETuple2(am_error, am_no_float);
    }
View Full Code Here

      throw ERT.badarg(arg);
    }
    binbytes = bin.getByteArray();
    String out = new String(binbytes);
   
    return new EString(out);
  }
View Full Code Here

          ESeq l = ERT.NIL;
          while (!list.isNil()) {
            EObject group = list.head();
            ESmall num;
            EAtom nam;
            EString nam2;
            if ((num=group.testSmall()) != null)
            {
              l = l.cons( capture (subject, mr, num.value, o2 ));
            } else if ((nam=group.testAtom()) != null) {
              Integer groupNo = o2.named_groups.get(nam.getName());
              if (groupNo != null) {
                l = l.cons( capture (subject, mr, groupNo.intValue(), o2 ));
              }
            } else if ((nam2=group.testString()) != null) {
              Integer groupNo = o2.named_groups.get(nam2.stringValue());
              if (groupNo != null) {
                l = l.cons( capture (subject, mr, groupNo.intValue(), o2 ));
              }
            } else {
              throw new NotImplemented("named capture groups");
View Full Code Here

 
  /** os:putenv(string(), string()) -> true */
  @BIF
  public static EObject putenv(EObject o1, EObject o2) {
    EString str1 = o1.testString();
    EString str2 = o2.testString();
    if (str1 == null || str2 == null)
      throw ERT.badarg(o1, o2);
   
    ErjangConfig.setenv(str1.stringValue(), str2.stringValue());
   
    return ERT.TRUE;
  }
View Full Code Here

  }
 
  /** os:getenv(string()) -> string() | false */
  @BIF
  public static EObject getenv(EObject o) {
    EString str = o.testString();
    if (str == null)
      throw ERT.badarg(o);

    String value;
   
    value = ErjangConfig.getenv(str.stringValue());
    if (value != null) {
      return EString.fromString(value);
    }
   
    value = System.getenv(str.stringValue());

    if (value == null) {
      return ERT.FALSE;
    } else {
      return EString.fromString(value);
View Full Code Here

TOP

Related Classes of erjang.EString

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.