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

28
LINES

< > BotCompany Repo | #1027854 // CIString - case insensitive string, compact version 1 [dev.]

JavaX fragment (include)

1  
sclass CIString implements Comparable<CIString>, CharSequence {
2  
  char[] data; // could be final except for persistence
3  
  
4  
  *() {}
5  
  *(char[] s) { data = String.valueOf(assertNotNull(s)); }
6  
  *(S s) { data = toCharArray(s); }
7  
  
8  
  // note that eq(s, cistring) is still false
9  
  public bool equals(Object o) {
10  
    if (o cast CIString)
11  
      ret eqicCharArrays(data, o.data);
12  
    /*if (o instanceof String) // One-way interoperability!
13  
      return s.equalsIgnoreCase((String) o);*/
14  
    false;
15  
  }
16  
  
17  
  public int compareTo(CIString cis) {
18  
    ret compareCharArraysIC(data, cis.data);
19  
  }
20  
  
21  
  toString { ret str(data); }
22  
  
23  
  public char charAt(int index) { ret data[index]; }
24  
  public int length() { ret data.length; }
25  
  public CharSequence subSequence(int start, int end) {
26  
    ret CIString(subCharArray(data, start, end));
27  
  }
28  
}

Author comment

Began life as a copy of #1002873

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1027854
Snippet name: CIString - case insensitive string, compact version 1 [dev.]
Eternal ID of this version: #1027854/1
Text MD5: ee12bd5946455debb3fdd98c7de99e98
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:08:42
Source code size: 857 bytes / 28 lines
Pitched / IR pitched: No / No
Views / Downloads: 175 / 207
Referenced in: [show references]