[mkgmap-dev] multi-word street search
From Andrzej Popowski popej at poczta.onet.pl on Mon Dec 15 18:21:51 GMT 2014
Hi, > seems to work well with --latin1, but --unicode still doesn't work. I have assumed, that name offset in MDR7 is in bytes, not in characters. Attached is a patch for mixed-index branch, which recalculate offset. It seems to work in Mapsource, both cp1250 and UTF-8, but please check on your examples. I haven't tested in device. -- Best regards, Andrzej -------------- next part -------------- --- src/uk/me/parabola/imgfmt/app/mdr/Mdr7.java 2014-12-15 13:02:46.823219100 +0100 +++ src/uk/me/parabola/imgfmt/app/mdr/Mdr7.java 2014-12-15 18:52:49.632720700 +0100 @@ -12,6 +12,8 @@ */ package uk.me.parabola.imgfmt.app.mdr; +import java.nio.charset.Charset; + import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -40,9 +42,11 @@ private List<Mdr7Record> streets = new ArrayList<>(); private final int u2size = 1; + private final Charset charset; public Mdr7(MdrConfig config) { setConfig(config); + charset = config.getSort().getCharset(); } public void addStreet(int mapId, String name, int lblOffset, int strOff, Mdr5Record mdrCity) { @@ -56,13 +60,9 @@ allStreets.add(st); boolean start = false; - int nameOffset = -1; - for (int i = 0; i < name.length() - 2; i++) { - char c = name.charAt(i); - if (c < ' ') - continue; - - nameOffset++; + int nameOffset = (name.charAt(0) < ' ')? 1: 0; + for (; nameOffset < name.length() - 2; nameOffset++) { + char c = name.charAt(nameOffset); if (Character.isWhitespace(c)) { start = true; @@ -83,8 +83,8 @@ st.setName(name); st.setCity(mdrCity); st.setNameOffset(nameOffset); - System.out.printf("%s %d\n", st.getName(), st.getNameOffset()); - System.out.println("add partial " + st.getPartialName()); + //System.out.printf("%s %d\n", st.getName(), st.getNameOffset()); + //System.out.println("add partial " + st.getPartialName()); allStreets.add(st); start = false; } @@ -262,8 +262,10 @@ if (hasStrings) putStringOffset(writer, s.getStringOffset()); - if (hasNameOffset) - writer.put((byte) (s.getNameOffset())); + if (hasNameOffset) { + byte skipName[] = name.substring(0, s.getNameOffset()).getBytes(charset); + writer.put((byte) (skipName.length)); + } putN(writer, u2size, trailingFlags); } --- src/uk/me/parabola/imgfmt/app/mdr/Mdr7Record.java 2014-12-15 13:02:46.823219100 +0100 +++ src/uk/me/parabola/imgfmt/app/mdr/Mdr7Record.java 2014-12-15 18:19:36.359019000 +0100 @@ -83,7 +83,7 @@ * @return A substring of name, starting at the nameOffset value. */ public String getPartialName() { - return nameOffset == 0 ? name : name.substring(nameOffset + ((name.charAt(0) < ' ')? 1: 0)); + return nameOffset == 0 ? name : name.substring(nameOffset); } public String toString() {
- Previous message: [mkgmap-dev] multi-word street search
- Next message: [mkgmap-dev] multi-word street search
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the mkgmap-dev mailing list