Skip to content

Commit

Permalink
feat: [cxx-parser] Add SimpleType.lenOfArrayType extension
Browse files Browse the repository at this point in the history
  • Loading branch information
littleGnAl committed Nov 20, 2023
1 parent 4247ef7 commit 91080bd
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 5 deletions.
4 changes: 0 additions & 4 deletions cxx-parser/__tests__/unit_test/cxx_terra_node_ext.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import fs from 'fs';
import os from 'os';
import path from 'path';

import '../../src/cxx_terra_node_ext';
import { SimpleType, SimpleTypeKind } from '../../src/cxx_terra_node';

Expand Down
2 changes: 1 addition & 1 deletion cxx-parser/src/cxx_terra_node.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';

import { TerraNode } from '@agoraio-extensions/terra-core';
import './cxx_terra_node_ext';
import './cxx_terra_node_string_ext';

function getAllClazzs(cxxfiles: CXXFile[]): Clazz[] {
return cxxfiles.flatMap((file) =>
Expand Down
53 changes: 53 additions & 0 deletions cxx-parser/src/cxx_terra_node_string_ext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
export {};

declare global {
export interface String {
/**
* This function removes the namespace from a fully qualified name.
* For example, "foo::bar" becomes "bar".
*/
trimNamespace(): string;

/**
* Returns the namespace of the class name.
*
* Example: "std::vector::size_type" returns "std::vector"
*/
getNamespace(): string;
}
}

/**
* This function removes the namespace from a fully qualified name.
* For example, "foo::bar" becomes "bar".
*/
String.prototype.trimNamespace = function (): string {
if (this.length === 0) {
return '';
}

if (!this.includes('::')) {
return this as string;
}

const splitted = this.split('::');
return splitted[splitted.length - 1];
};

/**
* Returns the namespace of the class name.
*
* Example: "std::vector::size_type" returns "std::vector"
*/
String.prototype.getNamespace = function (): string {
if (this.length === 0) {
return '';
}

if (!this.includes('::')) {
return '';
}

const splitted = this.split('::');
return Array.from(splitted.slice(0, splitted.length - 1)).join('::');
};
2 changes: 2 additions & 0 deletions cxx-parser/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// This should be above the `cxx_terra_node`, or it will throw TypeError: Cannot read properties of undefined (reading 'xxx')
export * from './cxx_terra_node_ext';
// This should be above the `cxx_terra_node`, or it will throw TypeError: Cannot read properties of undefined (reading 'xxx')
export * from './cxx_terra_node_string_ext';
export * from './cxx_terra_node';
export * from './cxx_parser_configs';
// This should be above the `cxx_parser`, or it will throw TypeError: Cannot read properties of undefined (reading 'xxx')
Expand Down

0 comments on commit 91080bd

Please sign in to comment.