codeformat4cj:基于多语言支持的代码格式化库项目

用户可借助此项目对多种编程语言代码进行格式化处理,提升代码可读性与规范性。该项目为自研库,支持C、C++、OC/OC++、js/ts、java、python等语言的格式化,具备便捷的API接口。【此简介由AI生成】

分支5Tags19
文件最后提交记录最后更新时间
2 天前
3 个月前
25 天前
25 天前
2 个月前
2 天前
3 个月前
2 天前
2 天前

codeformat4cj

介绍

codeformat4cj是一个代码格式化库,目前支持C、C++、OC/OC++、js/ts、Java、Python、Go、Html、Kotlin、Swift、Rust、C#、Dart、PHP、Cangjie、SQL、Scala、Bash等20种语言。

特性

本项目为自研项目

  • 🚀 支持C和C++代码格式化
  • 🚀 支持OC/OC++、js/ts、Java、Python、Go代码格式化
  • 🚀 支持Html、Go、Kotlin、Swift、Rust、C#、Dart、PHP、Cangjie、SQL、Scala、Bash代码格式化

源码目录

├── README.md                                 #整体介绍
├── CHANGELOG.md                              #更新说明
├── LICENSE                                   #license说明
├── doc                                       #文档目录
│   └── feature_api.md                        #API接口文档
├── src                                       #仓颉源码目录 
└── cjpm.toml                                 #项目的配置文件 

接口说明

主要类和函数接口说明详见 API

使用说明

编译构建

描述具体的编译过程:

    1.先通过命令把代码下载下来,
      git clone -b develop https://gitcode.com/Cangjie-TPC/codeformat4cj.git
    2.进入项目目录
      执行cjpm build即可编译通过      

功能示例

功能示例描述: 将一段C++代码格式化

示例代码如下:


    var codeRaw = """
    #include<stdio.h>
    #include<stdlib.h>
    struct Node{int data;struct Node*next;};struct Node*createNode(int data){struct Node*node=(struct Node*)malloc(sizeof(struct Node));node->data=data;node->next=NULL;return node;}void insert(struct Node**head,int data){struct Node*newNode=createNode(data);if(*head==NULL){*head=newNode;return;}struct Node*temp=*head;while(temp->next!=NULL){temp=temp->next;}temp->next=newNode;}void printList(struct Node*head){struct Node*temp=head;while(temp!=NULL){printf("%d ",temp->data);temp=temp->next;}printf("\\n");}void freeList(struct Node*head){struct Node*temp;while(head!=NULL){temp=head;head=head->next;free(temp);}}int main(){struct Node*head=NULL;int arr[]={7,3,9,1,4,6,2,8,5};int n=sizeof(arr)/sizeof(arr[0]);for(int i=0;i<n;i++){insert(&head,arr[i]);}printf("链表元素:");printList(head);int sum=0;for(int i=0;i<n;i++){sum+=arr[i];}printf("数组总和:%d\\n",sum);freeList(head);return 0;}
    """

    let output = codeFormat("cpp",codeRaw,FormatConfig())
    println(output)


```shell

输出结果如下:

```cangjie

#include<stdio.h>
#include<stdlib.h>
struct Node{
    int data;
    struct Node*next;
};
struct Node*createNode(int data){
    struct Node*node=(struct Node*)malloc(sizeof(struct Node));
    node->data=data;
    node->next=NULL;
    return node;
}
void insert(struct Node**head,int data){
    struct Node*newNode=createNode(data);
    if(*head==NULL){
        *head=newNode;
        return;
    }
    struct Node*temp=*head;
    while(temp->next!=NULL){
        temp=temp->next;
    }
    temp->next=newNode;
}
void printList(struct Node*head){
    struct Node*temp=head;
    while(temp!=NULL){
        printf("%d ",temp->data);
        temp=temp->next;
    }
    printf("\n");
}
void freeList(struct Node*head){
    struct Node*temp;
    while(head!=NULL){
        temp=head;
        head=head->next;
        free(temp);
    }
}
int main(){
    struct Node*head=NULL;
    int arr[]={7,3,9,1,4,6,2,8,5};
    int n=sizeof(arr)/sizeof(arr[0]);
    for(int i=0;i<n;i++){
        insert(&head,arr[i]);
    }
    printf("链表元素:");
    printList(head);
    int sum=0;
    for(int i=0;i<n;i++){
        sum+=arr[i];
    }
    printf("数组总和:%d\n",sum);
    freeList(head);
    return 0;
}

约束与限制

在下述版本验证通过:

编号 依赖构建工具 版本号
1 cjc v1.1.3

开源协议

本项目基于 Apache License 2.0 ,请自由地享受和参与开源。

参与贡献

欢迎给我们提交PR,欢迎给我们提交Issue,欢迎参与任何形式的贡献。

项目介绍

用户可借助此项目对多种编程语言代码进行格式化处理,提升代码可读性与规范性。该项目为自研库,支持C、C++、OC/OC++、js/ts、java、python等语言的格式化,具备便捷的API接口。【此简介由AI生成】

定制我的领域