1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "Declaration.h"
18 
19 #include <hidl-util/StringHelper.h>
20 #include <regex>
21 
22 namespace android {
23 
24 static const std::regex RE_LEADING_SPACES("\n +");
25 
Declaration(const std::string & name)26 Declaration::Declaration(const std::string &name)
27     : mName(name)
28     {}
29 
~Declaration()30 Declaration::~Declaration() {}
31 
getName() const32 const std::string& Declaration::getName() const {
33     return mName;
34 }
setName(const std::string & name)35 void Declaration::setName(const std::string &name) {
36     mName = name;
37 }
38 
forceCamelCase()39 void Declaration::forceCamelCase() {
40     mName = StringHelper::RTrim(mName, "_t");
41     mName = StringHelper::ToCamelCase(mName);
42 }
43 
forcePascalCase()44 void Declaration::forcePascalCase() {
45     mName = StringHelper::RTrim(mName, "_t");
46     mName = StringHelper::ToPascalCase(mName);
47 }
48 
forceUpperSnakeCase()49 void Declaration::forceUpperSnakeCase() {
50     mName = StringHelper::RTrim(mName, "_t");
51     mName = StringHelper::ToUpperSnakeCase(mName);
52 }
53 
getComment() const54 const std::string& Declaration::getComment() const {
55     return mComment;
56 }
setComment(const std::string & comment)57 void Declaration::setComment(const std::string &comment) {
58     // remove excess leading whitespace
59     mComment = regex_replace(comment, RE_LEADING_SPACES, "\n ");
60 }
61 
generateCommentText(Formatter & out) const62 void Declaration::generateCommentText(Formatter &out) const {
63     if (!mComment.empty()) {
64         out << mComment << "\n";
65     }
66 }
67 
generateParameterSource(Formatter & out) const68 void Declaration::generateParameterSource(Formatter &out) const {
69     out << "/* UNKNOWN PARAMTER */" << "\n";
70 }
71 
72 } //namespace android
73