blob: 894965cff1c58e8ae4fe4af1527d51360ff1c9fa [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");
41 mName = StringHelper::SnakeCaseToCamelCase(mName);
42}
43
44void Declaration::forcePascalCase() {
45 mName = StringHelper::RTrim(mName, "_t");
46 mName = StringHelper::SnakeCaseToPascalCase(mName);
47}
48
Steven Morelandf1a35f72016-08-17 08:41:49 -070049const std::string& Declaration::getComment() const {
50 return mComment;
51}
52void Declaration::setComment(const std::string &comment) {
53 // remove excess leading whitespace
54 mComment = regex_replace(comment, RE_LEADING_SPACES, "\n ");
55}
56
57void Declaration::generateCommentText(Formatter &out) const {
58 if (!mComment.empty()) {
59 out << mComment << "\n";
60 }
61}
62
63void Declaration::generateParameterSource(Formatter &out) const {
64 out << "/* UNKOWN PARAMTER */" << "\n";
65}
66
67} //namespace android