Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

54
LINES

< > BotCompany Repo | #1031656 // ManagedString

JavaX fragment (include) [tags: use-pretranspiled]

Uses 11335K of libraries. Click here for Pure Java version (5400L/33K).

sclass ManagedString extends AbstractManagedObject implements CharSequence {
  replace Addr with int.
  
  S value;
  
  // usable but doesn't handle null
  *(ManagedIntObjects_v1 mem, Addr *addr) {
    super(mem);
    value = mem.readString(addr);
  }
  
  // ...unless you call this
  bool isNull() { ret value == null; }
  
  // internal
  *(ManagedIntObjects_v1 mem, S *value, Addr *addr) {
    super(mem);
  }
  
  // for proper null handling
  static ManagedString load(ManagedIntObjects_v1 mem, Addr addr) {
    S value = mem.readString(addr);
    if (value == null) null;
    ret new ManagedString(mem, value, addr);
  }
  
  static ManagedString create(ManagedIntObjects_v1 mem, S value) {
    if (value == null) null;
    ret new ManagedString(mem, value, mem.newString(value));
  }

  // GC handling
  public void scanForCollection(IManagedObjectCollector gc) {
    gc.noteString(addr, lambda1 setAddr);
  } 
  
  @Override
  public char charAt(int index) {
    ret value.charAt(index);
  }

  @Override
  public int length() {
    ret l(value);
  }

  @Override
  public CharSequence subSequence(int start, int end) {
    ret value.substring(start, end);
  }

  @Override
  toString { ret value == null ? "" : value.toString(); }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1031656
Snippet name: ManagedString
Eternal ID of this version: #1031656/6
Text MD5: a8534770f7295cd51f87973b046a6012
Transpilation MD5: 61970a164832cbe8210a73b7c012ea51
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-06-25 08:23:18
Source code size: 1296 bytes / 54 lines
Pitched / IR pitched: No / No
Views / Downloads: 189 / 374
Version history: 5 change(s)
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)