blob: e252dd864ff3221185500a6bccbb7bd29d7265ce [file] [log] [blame]
Steven Morelandf1a35f72016-08-17 08:41:49 -07001/*
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
Steven Moreland95b46232016-09-20 14:46:55 -070019#include <hidl-util/StringHelper.h>
Steven Morelandf1a35f72016-08-17 08:41:49 -070020#include <regex>
21
22namespace android {
23
24static const std::regex RE_LEADING_SPACES("\n +");
25
26Declaration::Declaration(const std::string &name)
27 : mName(name)
28 {}
29
30Declaration::~Declaration() {}
31
32const std::string& Declaration::getName() const {
33 return mName;
34}
35void Declaration::setName(const std::string &name) {
36 mName = name;
37}
38
Steven Moreland95b46232016-09-20 14:46:55 -070039void Declaration::forceCamelCase() {
40 mName = StringHelper::RTrim(mName, "_t");
Yifan Hong42009032016-09-29 09:38:15 -070041 mName = StringHelper::ToCamelCase(mName);
Steven Moreland95b46232016-09-20 14:46:55 -070042}
43
44void Declaration::forcePascalCase() {
45 mName = StringHelper::RTrim(mName, "_t");
Yifan Hong42009032016-09-29 09:38:15 -070046 mName = StringHelper::ToPascalCase(mName);
47}
48
49void Declaration::forceUpperSnakeCase() {
50 mName = StringHelper::RTrim(mName, "_t");
51 mName = StringHelper::ToUpperSnakeCase(mName);
Steven Moreland95b46232016-09-20 14:46:55 -070052}
53
Steven Morelandf1a35f72016-08-17 08:41:49 -070054const std::string& Declaration::getComment() const {
55 return mComment;
56}
57void Declaration::setComment(const std::string &comment) {
58 // remove excess leading whitespace
59 mComment = regex_replace(comment, RE_LEADING_SPACES, "\n ");
60}
61
62void Declaration::generateCommentText(Formatter &out) const {
63 if (!mComment.empty()) {
64 out << mComment << "\n";
65 }
66}
67
68void Declaration::generateParameterSource(Formatter &out) const {
Yifan Hongb33b5ee2016-09-29 13:48:54 -070069 out << "/* UNKNOWN PARAMTER */" << "\n";
Steven Morelandf1a35f72016-08-17 08:41:49 -070070}
71
Yifan Hong42009032016-09-29 09:38:15 -070072} //namespace android