mirror of
https://github.com/lionsoul2014/ip2region.git
synced 2025-12-08 19:25:22 +00:00
return empty string for empty match
This commit is contained in:
parent
8f6effd8eb
commit
bd69a255fd
@ -7,10 +7,18 @@
|
||||
<dependency>
|
||||
<groupId>org.lionsoul</groupId>
|
||||
<artifactId>ip2region</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.1.1</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
### 关于查询结果
|
||||
定位信息查询 API 的原型为:
|
||||
```java
|
||||
String search(String ipStr) throw Exception;
|
||||
String search(byte[] ip) throw Exception;
|
||||
```
|
||||
查询出错会抛出异常,如果查询成功会返回字符串的 `region` 信息,如果指定的 ip 查询不到会返回空字符串 `""`,这对于自定义数据或者数据不完整的情况会出现。
|
||||
|
||||
### 关于 IPv4 和 IPv6
|
||||
该 xdb 查询客户端实现同时支持对 IPv4 和 IPv6 的查询,使用方式如下:
|
||||
```java
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
<groupId>org.lionsoul</groupId>
|
||||
<artifactId>ip2region</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.1.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>ip2region</name>
|
||||
|
||||
@ -124,8 +124,8 @@ public class Searcher {
|
||||
final int bytes = ip.length, dBytes = ip.length << 1;
|
||||
final int segIndexSize = version.segmentIndexSize;
|
||||
final byte[] buff = new byte[segIndexSize];
|
||||
int dataLen = -1;
|
||||
long dataPtr = -1, l = 0, h = (ePtr - sPtr) / segIndexSize;
|
||||
int dataLen = 0;
|
||||
long dataPtr = 0, l = 0, h = (ePtr - sPtr) / segIndexSize;
|
||||
while (l <= h) {
|
||||
long m = (l + h) >> 1;
|
||||
long p = sPtr + m * segIndexSize;
|
||||
@ -145,8 +145,8 @@ public class Searcher {
|
||||
|
||||
// empty match interception
|
||||
// System.out.printf("dataLen: %d, dataPtr: %d\n", dataLen, dataPtr);
|
||||
if (dataPtr < 0) {
|
||||
return null;
|
||||
if (dataLen == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// load and return the region data
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user