Java File Name Sanitize sanitizeBlankNodeName(String filename)

Here you can find the source of sanitizeBlankNodeName(String filename)

Description

Blank node names should start with a letter and have only letters/numbers.

License

Apache License

Parameter

Parameter Description
filename a parameter

Declaration

private static String sanitizeBlankNodeName(String filename) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*ww  w .j a  v a2 s.  c o m*/
     * Blank node names should start with a letter and have only
     * letters/numbers. TODO: Is there a case where we have two files that share
     * all letters/numbers in the same order?
     * 
     * @param filename
     * @return
     */
    private static String sanitizeBlankNodeName(String filename) {
        StringBuffer ret = new StringBuffer(filename.length());
        if (!filename.isEmpty()) {
            char charAt0 = filename.charAt(0);
            if (Character.isLetter(charAt0))
                ret.append(charAt0);
        }
        for (int i = 1; i < filename.length(); i++) {
            char ch = filename.charAt(i);
            if (Character.isLetterOrDigit(ch)) {
                ret.append(ch);
            }
        }
        return ret.toString();
    }
}

Related

  1. sanitize(String fileName)
  2. sanitizeFilename(String filename)
  3. sanitizeFileName(String filename)
  4. sanitizeFileName(String filename)
  5. sanitizeFilename(String fileName)