01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19:
20: package org.apache.axis2.wsdl.databinding;
21:
22: import java.text.Collator;
23: import java.util.Arrays;
24: import java.util.Locale;
25:
26: public class CUtils {
27:
28: static final String keywords[] = { "auto", "double", "int",
29: "struct", "break", "else", "long", "switch", "case",
30: "enum", "register", "typedef", "char", "extern", "return",
31: "union", "const", "float", "short", "unsigned", "continue",
32: "for", "signed", "void", "default", "goto", "sizeof",
33: "volatile", "do", "if", "static", "while" };
34:
35: /** Collator for comparing the strings */
36: static final Collator englishCollator = Collator
37: .getInstance(Locale.ENGLISH);
38:
39: /** Use this character as suffix */
40: static final char keywordPrefix = '_';
41:
42: /**
43: * Checks if the input string is a valid C keyword.
44: *
45: * @return Returns boolean.
46: */
47: public static boolean isCKeyword(String keyword) {
48: return (Arrays.binarySearch(keywords, keyword, englishCollator) >= 0);
49: }
50:
51: /**
52: * Turns a C keyword string into a non-C keyword string. (Right now this simply means appending
53: * an underscore.)
54: */
55: public static String makeNonCKeyword(String keyword) {
56: return keywordPrefix + keyword;
57: }
58:
59: }
|