1 /* 2 * Copyright (C) 2025 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 #ifndef SRC_TRACE_PROCESSOR_PERFETTO_SQL_INTRINSICS_FUNCTIONS_REPLACE_NUMBERS_FUNCTION_H_ 18 #define SRC_TRACE_PROCESSOR_PERFETTO_SQL_INTRINSICS_FUNCTIONS_REPLACE_NUMBERS_FUNCTION_H_ 19 20 #include <sqlite3.h> 21 22 #include "perfetto/base/status.h" 23 24 namespace perfetto { 25 namespace trace_processor { 26 27 class PerfettoSqlEngine; 28 class TraceProcessorContext; 29 30 // Registers the following functions: 31 // 32 // __intrinsic_strip_hex(name STRING, min_repeated_digits LONG) 33 // 34 // Description: 35 // Replaces hexadecimal sequences (with at least one digit) in a string with 36 // "<num>" based on specified criteria. 37 // 38 // Parameters: 39 // name STRING: The input string. 40 // min_repeated_digits LONG: MINIMUM consecutive hex characters for 41 // replacement. 42 // 43 // Replacement Criteria: 44 // - Replaces hex/num sequences [0-9a-fA-F] with at least one occurrence of a 45 // digit preceded by: 46 // - Start of the string 47 // - Defined prefix ("0x", "0X") 48 // - Non-alphanumeric character 49 // - Replaces only sequences with length >= 'min_repeated_digits' 50 // 51 // Return Value: 52 // The string with replaced hex sequences. 53 base::Status RegisterStripHexFunction(PerfettoSqlEngine* engine, 54 TraceProcessorContext* context); 55 56 // Implementation of __intrinsic_strip_hex function 57 // Visible for testing 58 std::string SqlStripHex(std::string input, int64_t min_repeated_digits); 59 } // namespace trace_processor 60 } // namespace perfetto 61 62 #endif // SRC_TRACE_PROCESSOR_PERFETTO_SQL_INTRINSICS_FUNCTIONS_REPLACE_NUMBERS_FUNCTION_H_ 63