MCPcopy Create free account
hub / github.com/diyhi/bbs / compare

Method compare

src/main/java/cms/utils/VersionCompare.java:15–52  ·  view source on GitHub ↗

比较 不含字母比较 例如:5.5.3和5.7.10 @param v1 版本号 @param v2 版本号 @return

(String v1,String v2)

Source from the content-addressed store, hash-verified

13 * @return
14 */
15 public static int compare(String v1,String v2){
16 int i=0,j=0,x=0,y=0;
17 int v1Len=v1.length();
18 int v2Len=v2.length();
19 char c;
20 do {
21 while(i<v1Len){//计算出V1中的点之前的数字
22 c=v1.charAt(i++);
23 if(c>='0' && c<='9'){
24 x=x*10+(c-'0');//c-‘0’表示两者的ASCLL差值
25 }else if(c=='.'){
26 break;//结束
27 }else{
28 //无效的字符
29 }
30 }
31 while(j<v2Len){//计算出V2中的点之前的数字
32 c=v2.charAt(j++);
33 if(c>='0' && c<='9'){
34 y=y*10+(c-'0');
35 }else if(c=='.'){
36 break;//结束
37 }else{
38 //无效的字符
39 }
40 }
41 if(x<y){
42 return -1;
43 }else if(x>y){
44 return 1;
45 }else{
46 x=0;y=0;
47 continue;
48 }
49
50 } while ((i<v1Len) || (j<v2Len));
51 return 0;
52 }
53
54}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected