< prev index next >

src/jdk.jextract/share/classes/com/sun/tools/jextract/Utils.java

Print this page




 235                 fillBuiltinRecordTypes(type.getPointeeType(), recordTypes);
 236                 break;
 237 
 238             case Unexposed:
 239             case Elaborated:
 240             case Typedef:
 241                 fillBuiltinRecordTypes(type, recordTypes);
 242                 break;
 243 
 244             default: // nothing to do
 245         }
 246     }
 247 
 248     // return the absolute path of the library of given name by searching
 249     // in the given array of paths.
 250     public static Optional<Path> findLibraryPath(Path[] paths, String libName) {
 251         return Arrays.stream(paths).
 252                 map(p -> p.resolve(System.mapLibraryName(libName))).
 253                 filter(Files::isRegularFile).map(Path::toAbsolutePath).findFirst();
 254     }














































 255 }


 235                 fillBuiltinRecordTypes(type.getPointeeType(), recordTypes);
 236                 break;
 237 
 238             case Unexposed:
 239             case Elaborated:
 240             case Typedef:
 241                 fillBuiltinRecordTypes(type, recordTypes);
 242                 break;
 243 
 244             default: // nothing to do
 245         }
 246     }
 247 
 248     // return the absolute path of the library of given name by searching
 249     // in the given array of paths.
 250     public static Optional<Path> findLibraryPath(Path[] paths, String libName) {
 251         return Arrays.stream(paths).
 252                 map(p -> p.resolve(System.mapLibraryName(libName))).
 253                 filter(Files::isRegularFile).map(Path::toAbsolutePath).findFirst();
 254     }
 255 
 256     /*
 257      * FIXME: when we add jdk.compiler dependency from jdk.jextract module, revisit
 258      * the following. The following methods 'quote', 'quote' and 'isPrintableAscii'
 259      * are from javac source. See also com.sun.tools.javac.util.Convert.java.
 260      */
 261 
 262     /**
 263      * Escapes each character in a string that has an escape sequence or
 264      * is non-printable ASCII.  Leaves non-ASCII characters alone.
 265      */
 266     public static String quote(String s) {
 267         StringBuilder buf = new StringBuilder();
 268         for (int i = 0; i < s.length(); i++) {
 269             buf.append(quote(s.charAt(i)));
 270         }
 271         return buf.toString();
 272     }
 273 
 274     /**
 275      * Escapes a character if it has an escape sequence or is
 276      * non-printable ASCII.  Leaves non-ASCII characters alone.
 277      */
 278     public static String quote(char ch) {
 279         switch (ch) {
 280         case '\b':  return "\\b";
 281         case '\f':  return "\\f";
 282         case '\n':  return "\\n";
 283         case '\r':  return "\\r";
 284         case '\t':  return "\\t";
 285         case '\'':  return "\\'";
 286         case '\"':  return "\\\"";
 287         case '\\':  return "\\\\";
 288         default:
 289             return (isPrintableAscii(ch))
 290                 ? String.valueOf(ch)
 291                 : String.format("\\u%04x", (int) ch);
 292         }
 293     }
 294 
 295     /**
 296      * Is a character printable ASCII?
 297      */
 298     private static boolean isPrintableAscii(char ch) {
 299         return ch >= ' ' && ch <= '~';
 300     }
 301 }
< prev index next >