2 * Copyright 2004-present Facebook, Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <folly/Range.h>
23 * The LogName class contains utility functions for processing log category
24 * names. It primarily handles canonicalization of names.
26 * For instance, "foo.bar", "foo..bar", and ".foo.bar..." all refer to the same
32 * Return a canonicalized version of the log name.
34 * Leading and trailing '.' characters are removed, and all sequences of
35 * consecutive '.' characters are replaced with a single '.'
37 static std::string canonicalize(folly::StringPiece name);
42 * The log name does not need to be pre-canonicalized.
43 * The hash for equivalent log names will always be equal.
45 static size_t hash(folly::StringPiece name);
48 * Compare two log names.
50 * The log name does not need to be pre-canonicalized.
51 * Returns 0 if and only if the two names refer to the same log category.
52 * Otherwise, returns -1 if the canonical version of nameA is less than the
53 * canonical version of nameB.
55 static int cmp(folly::StringPiece nameA, folly::StringPiece nameB);
58 * Get the name of the parent log category.
60 * Returns a StringPiece pointing into the input data.
61 * As a result, the parent log name may not be canonical if the input log
62 * name is not already canonical.
64 * If the input log name refers to the root log category, an empty
65 * StringPiece will be returned.
67 static folly::StringPiece getParent(folly::StringPiece name);
70 * Hash functor that can be used with standard library containers.
73 size_t operator()(folly::StringPiece key) const {
74 return LogName::hash(key);
79 * Equality functor that can be used with standard library containers.
82 bool operator()(folly::StringPiece a, folly::StringPiece b) const {
83 return LogName::cmp(a, b) == 0;