Ticket #24446: 24446-2.patch
File 24446-2.patch, 2.0 KB (added by , 12 days ago) |
---|
-
src/org/openstreetmap/josm/actions/upload/ApiPreconditionCheckerHook.java
73 73 Long.toString(osmPrimitive.getId()) 74 74 ) 75 75 ); 76 osmPrimitive.put(key, Utils. shortenString(value, Tagged.MAX_TAG_LENGTH));76 osmPrimitive.put(key, Utils.reduceCodePoints(value, Tagged.MAX_TAG_LENGTH)); 77 77 continue; 78 78 } 79 79 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), … … 106 106 } 107 107 return true; 108 108 } 109 109 110 } -
src/org/openstreetmap/josm/tools/Utils.java
2049 2049 public static boolean checkCodePointCount(String s, int maxLen) { 2050 2050 return getCodePointCount(s) <= maxLen; 2051 2051 } 2052 2053 /** 2054 * Truncate a string to the given maximum number of code points. 2055 * @param s the string 2056 * @param num the maximum number of code points 2057 * @return s if it is null or the number of code points is within the given limit, else a string with the first {@code num} 2058 * code points 2059 * @since xxx 2060 */ 2061 public static String reduceCodePoints(String s, int num) { 2062 if (checkCodePointCount(s, num)) 2063 return s; 2064 String[] parts = s.split("\\b{g}"); // split along grapheme cluster boundaries 2065 StringBuilder shorter = new StringBuilder(); 2066 for (int i = 0; i < num; i++) { 2067 shorter.append(parts[i]); 2068 } 2069 return shorter.toString(); 2070 } 2071 2052 2072 }