com.google.common.base.Ascii类的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(289)

本文整理了Java中com.google.common.base.Ascii类的一些代码示例,展示了Ascii类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ascii类的具体详情如下:
包路径:com.google.common.base.Ascii
类名称:Ascii

Ascii介绍

[英]Static methods pertaining to ASCII characters (those in the range of values 0x00 through 0x7F), and to strings containing such characters.

ASCII utilities also exist in other classes of this package:

  • Charsets#US_ASCII specifies the Charset of ASCII characters.
  • CharMatcher#ASCII matches ASCII characters and provides text processing methods which operate only on the ASCII characters of a string.
    [中]与ASCII字符(值范围为0x00到0x7F)和包含此类字符的字符串相关的静态方法。
    ASCII实用程序也存在于该软件包的其他类中:
    *字符集#US#ASCII指定ASCII字符的字符集。
    *CharMatcher#ASCII匹配ASCII字符,并提供仅对字符串的ASCII字符进行操作的文本处理方法。

代码示例

代码示例来源:origin: google/guava

private static String normalizeToken(String token) {
 checkArgument(TOKEN_MATCHER.matchesAllOf(token));
 return Ascii.toLowerCase(token);
}

代码示例来源:origin: google/guava

private static String firstCharOnlyToUpper(String word) {
  return word.isEmpty()
    ? word
    : Ascii.toUpperCase(word.charAt(0)) + Ascii.toLowerCase(word.substring(1));
 }
}

代码示例来源:origin: google/guava

private boolean hasUpperCase() {
 for (char c : chars) {
  if (Ascii.isUpperCase(c)) {
   return true;
  }
 }
 return false;
}

代码示例来源:origin: immutables/immutables

public String apply(String input) {
  if (!input.isEmpty()) {
   if (this == CAPITALIZED && !Ascii.isUpperCase(input.charAt(0))) {
    return CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, input);
   }
   if (this == LOWERIZED && !Ascii.isLowerCase(input.charAt(0))) {
    return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, input);
   }
  }
  return input;
 }
}

代码示例来源:origin: google/guava

public void testCharsLower() {
 for (char c : LOWER.toCharArray()) {
  String str = String.valueOf(c);
  assertTrue(str, c == Ascii.toLowerCase(c));
  assertFalse(str, c == Ascii.toUpperCase(c));
  assertTrue(str, Ascii.isLowerCase(c));
  assertFalse(str, Ascii.isUpperCase(c));
 }
}

代码示例来源:origin: google/guava

/** Constructor used to implement {@link #from(String)}, and from subclasses. */
InternetDomainName(String name) {
 // Normalize:
 // * ASCII characters to lowercase
 // * All dot-like characters to '.'
 // * Strip trailing '.'
 name = Ascii.toLowerCase(DOTS_MATCHER.replaceFrom(name, '.'));
 if (name.endsWith(".")) {
  name = name.substring(0, name.length() - 1);
 }
 checkArgument(name.length() <= MAX_LENGTH, "Domain name too long: '%s':", name);
 this.name = name;
 this.parts = ImmutableList.copyOf(DOT_SPLITTER.split(name));
 checkArgument(parts.size() <= MAX_PARTS, "Domain has too many parts: '%s'", name);
 checkArgument(validateSyntax(parts), "Not a valid domain name: '%s'", name);
 this.publicSuffixIndex = findSuffixOfType(Optional.<PublicSuffixType>absent());
 this.registrySuffixIndex = findSuffixOfType(Optional.of(PublicSuffixType.REGISTRY));
}

代码示例来源:origin: google/guava

@Override
String normalizeWord(String word) {
 return Ascii.toLowerCase(word);
}

代码示例来源:origin: line/armeria

@VisibleForTesting
static String toHeaderName(String name) {
  requireNonNull(name, "name");
  checkArgument(!name.isEmpty(), "name is empty");
  final String upperCased = Ascii.toUpperCase(name);
  if (name.equals(upperCased)) {
    return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, name);
  }
  final String lowerCased = Ascii.toLowerCase(name);
  if (name.equals(lowerCased)) {
    return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, name);
  }
  // Ensure that the name does not contain '_'.
  // If it contains '_', we give up to make it lower hyphen case. Just converting it to lower case.
  if (name.indexOf('_') >= 0) {
    return lowerCased;
  }
  if (Ascii.isUpperCase(name.charAt(0))) {
    return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, name);
  } else {
    return CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, name);
  }
}

代码示例来源:origin: google/guava

@Override
String normalizeWord(String word) {
 return Ascii.toUpperCase(word);
}

代码示例来源:origin: google/error-prone

&& Ascii.isUpperCase(identifier.charAt(1))
 && Ascii.isLowerCase(identifier.charAt(2))) {
if (Ascii.toUpperCase(token).equals(identifier)) {
 return upperCamelToken(token) + "T";

代码示例来源:origin: google/guava

private boolean hasLowerCase() {
 for (char c : chars) {
  if (Ascii.isLowerCase(c)) {
   return true;
  }
 }
 return false;
}

代码示例来源:origin: google/guava

@Override
 public String toString() {
  return "CharSource.wrap(" + Ascii.truncate(seq, 30, "...") + ")";
 }
}

代码示例来源:origin: google/guava

continue;
int alphaIndex = getAlphaIndex(c1);
if (alphaIndex < 26 && alphaIndex == getAlphaIndex(c2)) {
 continue;

代码示例来源:origin: google/guava

public void testCharsUpper() {
 for (char c : UPPER.toCharArray()) {
  String str = String.valueOf(c);
  assertFalse(str, c == Ascii.toLowerCase(c));
  assertTrue(str, c == Ascii.toUpperCase(c));
  assertFalse(str, Ascii.isLowerCase(c));
  assertTrue(str, Ascii.isUpperCase(c));
 }
}

代码示例来源:origin: google/j2objc

/** Constructor used to implement {@link #from(String)}, and from subclasses. */
InternetDomainName(String name) {
 // Normalize:
 // * ASCII characters to lowercase
 // * All dot-like characters to '.'
 // * Strip trailing '.'
 name = Ascii.toLowerCase(DOTS_MATCHER.replaceFrom(name, '.'));
 if (name.endsWith(".")) {
  name = name.substring(0, name.length() - 1);
 }
 checkArgument(name.length() <= MAX_LENGTH, "Domain name too long: '%s':", name);
 this.name = name;
 this.parts = ImmutableList.copyOf(DOT_SPLITTER.split(name));
 checkArgument(parts.size() <= MAX_PARTS, "Domain has too many parts: '%s'", name);
 checkArgument(validateSyntax(parts), "Not a valid domain name: '%s'", name);
 this.publicSuffixIndex = findSuffixOfType(Optional.<PublicSuffixType>absent());
 this.registrySuffixIndex = findSuffixOfType(Optional.of(PublicSuffixType.REGISTRY));
}

代码示例来源:origin: google/guava

@Override
String normalizeWord(String word) {
 return Ascii.toLowerCase(word);
}

代码示例来源:origin: google/j2objc

@Override
String normalizeWord(String word) {
 return Ascii.toUpperCase(word);
}

代码示例来源:origin: google/guava

/**
 * If the argument is a {@linkplain #isLowerCase(char) lowercase ASCII character} returns the
 * uppercase equivalent. Otherwise returns the argument.
 */
public static char toUpperCase(char c) {
 return isLowerCase(c) ? (char) (c ^ CASE_MASK) : c;
}

代码示例来源:origin: immutables/immutables

private static boolean shouldDisableFor(Reporter reporter, Element element) {
  while (element != null) {
   if (element.getKind() == ElementKind.PACKAGE) {
    for (String segment : DOT_SPLITTER.split(((PackageElement) element).getQualifiedName())) {
     if (!segment.isEmpty() && Ascii.isUpperCase(segment.charAt(0))) {
      reporter.warning(About.INCOMPAT, WARNING_START + " uppercase package names");
      return true;
     }
    }
   }
   if (element.getKind().isClass() || element.getKind().isInterface()) {
    if (Ascii.isLowerCase(element.getSimpleName().charAt(0))) {
     reporter.warning(About.INCOMPAT, WARNING_START + " lowercase class names");
     return true;
    }
   }
   element = element.getEnclosingElement();
  }
  return false;
 }
}

代码示例来源:origin: google/j2objc

@Override
 public String toString() {
  return "CharSource.wrap(" + Ascii.truncate(seq, 30, "...") + ")";
 }
}

相关文章