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

34
LINES

< > BotCompany Repo | #1002873 // CIString - case insensitive string

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

Libraryless. Click here for Pure Java version (2509L/16K).

// the problem with this is the lack of a contract-compliant hashCode()
sclass CIString implements Comparable<CIString>, CharSequence {
  S s; // final
  
  *() {}
  *(S *s) { assertNotNull(s); }
  
  // note that eq(s, cistring) is still false
  public boolean equals(Object o) {
    if (o instanceof CIString)
      return s.equalsIgnoreCase(((CIString) o).s);
    if (o instanceof String) // One-way interoperability!
      return s.equalsIgnoreCase((String) o);
    return false;
  }
  
  public int compareTo(CIString cis) {
    ret s.compareToIgnoreCase(cis.s);
  }
  
  public S toString() {
    ret s;
  }
  
  public S str() {
    ret s;
  }
  
  public char charAt(int index) { ret s.charAt(index); }
  public int length() { ret s.length(); }
  public CharSequence subSequence(int start, int end) {
    ret CIString(s.substring(start, end));
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1002873
Snippet name: CIString - case insensitive string
Eternal ID of this version: #1002873/4
Text MD5: c785a9ef33e5453b76281e19e2648cc8
Transpilation MD5: 6ce7f3365207a13aeced3a3def653886
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-04-15 19:24:35
Source code size: 890 bytes / 34 lines
Pitched / IR pitched: No / No
Views / Downloads: 579 / 1576
Version history: 3 change(s)
Referenced in: [show references]