Project

Profile

Help

Revision ac9bb22d

Added by Michael Kay over 9 years ago

Fix bug #1493 diagnostics for invalid xs:Name

View differences:

latest9.4/hej/net/sf/saxon/type/StringConverter.java
413 413
            }
414 414
        }
415 415
        /*@Nullable*/ public ValidationFailure validate(/*@NotNull*/ CharSequence input) {
416
            String in = input.toString();
417
            if (in.indexOf(':') >= 0) {
418
                // replace any colons by underscores and then test if it's a valid NCName
419
                FastStringBuffer buff = new FastStringBuffer(in.length());
420
                buff.append(in);
421
                for (int i = 0; i < buff.length(); i++) {
422
                    if (buff.charAt(i) == ':') {
423
                        buff.setCharAt(i, '_');
424
                    }
416
            // if it's valid as an NCName then it's OK
417
            CharSequence trimmed = Whitespace.trimWhitespace(input);
418
            if (checker.isValidNCName(trimmed)) {
419
                return null;
420
            }
421

  
422
            // if not, replace any colons by underscores and then test if it's a valid NCName
423
            FastStringBuffer buff = new FastStringBuffer(trimmed.length());
424
            buff.append(trimmed);
425
            for (int i = 0; i < buff.length(); i++) {
426
                if (buff.charAt(i) == ':') {
427
                    buff.setCharAt(i, '_');
425 428
                }
426
                return super.validate(buff);
429
            }
430
            if (checker.isValidNCName(buff)) {
431
                return null;
427 432
            } else {
428
                return super.validate(in);
433
                return new ValidationFailure("The value '" + trimmed + "' is not a valid xs:Name");
429 434
            }
430 435
        }
431 436
    }

Also available in: Unified diff