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).

1  
// the problem with this is the lack of a contract-compliant hashCode()
2  
sclass CIString implements Comparable<CIString>, CharSequence {
3  
  S s; // final
4  
  
5  
  *() {}
6  
  *(S *s) { assertNotNull(s); }
7  
  
8  
  // note that eq(s, cistring) is still false
9  
  public boolean equals(Object o) {
10  
    if (o instanceof CIString)
11  
      return s.equalsIgnoreCase(((CIString) o).s);
12  
    if (o instanceof String) // One-way interoperability!
13  
      return s.equalsIgnoreCase((String) o);
14  
    return false;
15  
  }
16  
  
17  
  public int compareTo(CIString cis) {
18  
    ret s.compareToIgnoreCase(cis.s);
19  
  }
20  
  
21  
  public S toString() {
22  
    ret s;
23  
  }
24  
  
25  
  public S str() {
26  
    ret s;
27  
  }
28  
  
29  
  public char charAt(int index) { ret s.charAt(index); }
30  
  public int length() { ret s.length(); }
31  
  public CharSequence subSequence(int start, int end) {
32  
    ret CIString(s.substring(start, end));
33  
  }
34  
}

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: 647 / 1668
Version history: 3 change(s)
Referenced in: [show references]