首次提交
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.idea
|
||||||
34
README.md
Normal file
34
README.md
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
# Messenger SDK 开发文档
|
||||||
|
|
||||||
|
感谢您的访问.
|
||||||
|
本站旨在为Messenger开发者提供清晰的入门资料.
|
||||||
|
|
||||||
|
## 版权声明
|
||||||
|
本站内容作者为 Ling 和为本项目贡献内容、提出意见的朋友. 部分文献资料若涉及转载或引用, 将会在相关内容处标记.
|
||||||
|
|
||||||
|
文档中代码均以Apache 2.0开源, 包括正文部分插入代码.
|
||||||
|
本作品采用知识共享署名-非商业性使用-禁止演绎 3.0 中国大陆许可协议进行许可。
|
||||||
|
|
||||||
|
若需转载任何内容, 请详细注明出处, 仅供学习交流使用, 谢绝商业化使用.
|
||||||
|
|
||||||
|
本站图片资源部分来自互联网,仅学习交流使用. 部分图片由 Ling 绘制.
|
||||||
|
|
||||||
|
|
||||||
|
## 前言
|
||||||
|
|
||||||
|
SDK使用C++编写,使用Messenger SDK需要一定的C++基础。
|
||||||
|
如果你对C++还一知半解,那么阅读文档会比较吃力,建议有了一定水平以后再来阅读。
|
||||||
|
|
||||||
|
在本章节之后,我们假定你已经掌握了C++的基本语法,除了一些较为难以理解的部分之外,不会过多赘述语法上的问题,望理解。
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## 免责声明
|
||||||
|
|
||||||
|
本文档仅仅用来指导您如何使用Messenger SDK,我们对您使用Messenger SDK进行的一切行为不承担任何责任,
|
||||||
|
由此导致的一切后果由您自行承担。
|
||||||
|
如果您不能认可以上内容,请立即**关闭此文档**。
|
||||||
|
|
||||||
|
当您打开本章节之后的内容,我们视为你已经认可了我们的免责声明。
|
||||||
|
|
||||||
|
|
||||||
93
doc/entry.md
Normal file
93
doc/entry.md
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
# 快速入门
|
||||||
|
|
||||||
|
Messenger SDK一般是一个如下格式的压缩包
|
||||||
|
|
||||||
|
/libs
|
||||||
|
/arm64-v8a
|
||||||
|
/x86-64
|
||||||
|
/Windows
|
||||||
|
/Linux
|
||||||
|
...
|
||||||
|
/include
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
|
其中,libs下放置的是一些静态连接库,包含Android、Linux以及Windows。你需要将这些静态链接库链接到您的项目中,
|
||||||
|
并且在您项目的头文件搜索路径中添加 *include* 文件夹。
|
||||||
|
|
||||||
|
然后,你将可以使用Messenger的API了。
|
||||||
|
|
||||||
|
## 使用方法
|
||||||
|
|
||||||
|
Messenger SDK的主要class是 ling::Messenger ,它提供了服务器全部API的抽象。
|
||||||
|
它由ling::Client派生而来,ling::Client实现了服务器的通讯协议,包括STL握手过程。
|
||||||
|
|
||||||
|
> ling::Messenger以及ling::Client,都具有ling前缀,在C++中,这叫命名空间(*namespace*)。SDK内全部的class都在ling命名空间下。
|
||||||
|
|
||||||
|
|
||||||
|
ling::Messenger将是您接触最多的class。
|
||||||
|
它有两个构造函数:
|
||||||
|
|
||||||
|
~~~cpp
|
||||||
|
namespace ling{
|
||||||
|
class Messenger : public Client {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* 创建一个Messenger实例,创建实例时,即连接到Server。
|
||||||
|
*
|
||||||
|
* @param host 服务器host
|
||||||
|
* @param port 端口号
|
||||||
|
* @param projectId 项目id
|
||||||
|
* @throw ConnectException 在连接失败时
|
||||||
|
*/
|
||||||
|
Messenger(std::string host, int port, uint64_t projectId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 此重载相比上面的定义,额外需要一个deviceUid参数。
|
||||||
|
* 这是设备识别码,上面的实现将会自动读取设备识别码,但是可能不会唯一
|
||||||
|
* 扛攻击的能力较弱,如果设备拥有root权限则很可能被修改
|
||||||
|
* 所以,如果你有更加适合你需求的方案识别设备,将它作为第四个参数传递进来!
|
||||||
|
*
|
||||||
|
* @param host 服务器host
|
||||||
|
* @param port 端口号
|
||||||
|
* @param projectId 项目id
|
||||||
|
* @param deviceUid 设备识别码
|
||||||
|
* @throw ConnectException 在连接失败时
|
||||||
|
*/
|
||||||
|
Messenger(std::string host, int port, uint64_t projectId, std::string deviceUid);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
~~~
|
||||||
|
|
||||||
|
> 以后您会经常看到像这样的声明,提前熟悉它!
|
||||||
|
|
||||||
|
在Messenger创建完毕后,你可以通过它来和服务器交互。
|
||||||
|
|
||||||
|
## 范例
|
||||||
|
|
||||||
|
~~~ cpp
|
||||||
|
//别忘了导入定义!
|
||||||
|
#include <Messenger.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
//因为Messenger每次创建都会连接到服务器
|
||||||
|
//所以你不能每次和服务器交互都创建一个实例,而是必须复用!
|
||||||
|
//此处使用一个智能指针来管理Messenger的实例
|
||||||
|
//手动将没有初始值的指针赋值为nullptr,这是一个良好的编程习惯。
|
||||||
|
static std::shared_ptr<ling::Messenger> api = nullptr;
|
||||||
|
|
||||||
|
int main(void){
|
||||||
|
try{
|
||||||
|
//这里使用make_shared自动构造智能指针
|
||||||
|
::api = std::make_shared<ling::Messenger>("127.0.0.1",2019,1);
|
||||||
|
//在此时已经成功连接到服务器,可以进行交互。
|
||||||
|
//注意,交互之前必须进行设备注册,这个后面的章节在说。
|
||||||
|
} catch (const ling::ConnectException & e){
|
||||||
|
//还记得上面的声明中提到连接失败时会抛出ConnectException吗?
|
||||||
|
std::cerr << "连接服务器失败" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
~~~
|
||||||
|
|
||||||
1
doc/error.md
Normal file
1
doc/error.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# 异常
|
||||||
9
docsify-copy-code.js
Normal file
9
docsify-copy-code.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
/*!
|
||||||
|
* docsify-copy-code
|
||||||
|
* v2.1.1
|
||||||
|
* https://github.com/jperasmus/docsify-copy-code
|
||||||
|
* (c) 2017-2020 JP Erasmus <jperasmus11@gmail.com>
|
||||||
|
* MIT license
|
||||||
|
*/
|
||||||
|
!function(){"use strict";function s(o){return(s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o})(o)}!function(o,e){void 0===e&&(e={});var t=e.insertAt;if(o&&"undefined"!=typeof document){var n=document.head||document.getElementsByTagName("head")[0],c=document.createElement("style");c.type="text/css","top"===t&&n.firstChild?n.insertBefore(c,n.firstChild):n.appendChild(c),c.styleSheet?c.styleSheet.cssText=o:c.appendChild(document.createTextNode(o))}}(".docsify-copy-code-button,.docsify-copy-code-button span{cursor:pointer;transition:all .25s ease}.docsify-copy-code-button{position:absolute;z-index:1;top:0;right:0;overflow:visible;padding:.65em .8em;border:0;border-radius:0;outline:0;font-size:1em;background:grey;background:var(--theme-color,grey);color:#fff;opacity:0}.docsify-copy-code-button span{border-radius:3px;background:inherit;pointer-events:none}.docsify-copy-code-button .error,.docsify-copy-code-button .success{position:absolute;z-index:-100;top:50%;right:0;padding:.5em .65em;font-size:.825em;opacity:0;-webkit-transform:translateY(-50%);transform:translateY(-50%)}.docsify-copy-code-button.error .error,.docsify-copy-code-button.success .success{right:100%;opacity:1;-webkit-transform:translate(-115%,-50%);transform:translate(-115%,-50%)}.docsify-copy-code-button:focus,pre:hover .docsify-copy-code-button{opacity:1}"),document.querySelector('link[href*="docsify-copy-code"]')&&console.warn("[Deprecation] Link to external docsify-copy-code stylesheet is no longer necessary."),window.DocsifyCopyCodePlugin={init:function(){return function(o,e){o.ready(function(){console.warn("[Deprecation] Manually initializing docsify-copy-code using window.DocsifyCopyCodePlugin.init() is no longer necessary.")})}}},window.$docsify=window.$docsify||{},window.$docsify.plugins=[function(o,r){o.doneEach(function(){var o=Array.apply(null,document.querySelectorAll("pre[data-lang]")),c={buttonText:"复制代码",errorText:"Error",successText:"Copied"};r.config.copyCode&&Object.keys(c).forEach(function(t){var n=r.config.copyCode[t];"string"==typeof n?c[t]=n:"object"===s(n)&&Object.keys(n).some(function(o){var e=-1<location.href.indexOf(o);return c[t]=e?n[o]:c[t],e})});var e=['<button class="docsify-copy-code-button">','<span class="label">'.concat(c.buttonText,"</span>"),'<span class="error">'.concat(c.errorText,"</span>"),'<span class="success">'.concat(c.successText,"</span>"),"</button>"].join("");o.forEach(function(o){o.insertAdjacentHTML("beforeend",e)})}),o.mounted(function(){document.querySelector(".content").addEventListener("click",function(o){if(o.target.classList.contains("docsify-copy-code-button")){var e="BUTTON"===o.target.tagName?o.target:o.target.parentNode,t=document.createRange(),n=e.parentNode.querySelector("code"),c=window.getSelection();t.selectNode(n),c.removeAllRanges(),c.addRange(t);try{document.execCommand("copy")&&(e.classList.add("success"),setTimeout(function(){e.classList.remove("success")},1e3))}catch(o){console.error("docsify-copy-code: ".concat(o)),e.classList.add("error"),setTimeout(function(){e.classList.remove("error")},1e3)}"function"==typeof(c=window.getSelection()).removeRange?c.removeRange(t):"function"==typeof c.removeAllRanges&&c.removeAllRanges()}})})}].concat(window.$docsify.plugins||[])}();
|
||||||
|
//# sourceMappingURL=docsify-copy-code.min.js.map
|
||||||
1
docsify-pagination.min.js
vendored
Normal file
1
docsify-pagination.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
docsify-sidebar-collapse.min.js
vendored
Normal file
1
docsify-sidebar-collapse.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
!function(e){("object"!=typeof exports||"undefined"==typeof module)&&"function"==typeof define&&define.amd?define(e):e()}(function(){"use strict";function e(e,n){var t,a=(n=void 0===n?{}:n).insertAt;e&&"undefined"!=typeof document&&(t=document.head||document.getElementsByTagName("head")[0],(n=document.createElement("style")).type="text/css","top"===a&&t.firstChild?t.insertBefore(n,t.firstChild):t.appendChild(n),n.styleSheet?n.styleSheet.cssText=e:n.appendChild(document.createTextNode(e)))}var t;function a(e){e&&null!=t&&(e=e.getBoundingClientRect().top,document.querySelector(".sidebar").scrollBy(0,e-t))}function n(){requestAnimationFrame(function(){var e=document.querySelector(".app-sub-sidebar > .active");if(e)for(e.parentNode.parentNode.querySelectorAll(".app-sub-sidebar").forEach(function(e){return e.classList.remove("open")});e.parentNode.classList.contains("app-sub-sidebar")&&!e.parentNode.classList.contains("open");)e.parentNode.classList.add("open"),e=e.parentNode})}function o(e){t=e.target.getBoundingClientRect().top;var n=d(e.target,"LI",2);n&&(n.classList.contains("open")?(n.classList.remove("open"),setTimeout(function(){n.classList.add("collapse")},0)):(function(e){if(e)for(e.classList.remove("open","active");e&&"sidebar-nav"!==e.className&&e.parentNode;)"LI"!==e.parentNode.tagName&&"app-sub-sidebar"!==e.parentNode.className||e.parentNode.classList.remove("open"),e=e.parentNode}(s()),i(n),setTimeout(function(){n.classList.remove("collapse")},0)),a(n))}function s(){var e=document.querySelector(".sidebar-nav .active");return e||(e=d(document.querySelector('.sidebar-nav a[href="'.concat(decodeURIComponent(location.hash).replace(/ /gi,"%20"),'"]')),"LI",2))&&e.classList.add("active"),e}function i(e){if(e)for(e.classList.add("open","active");e&&"sidebar-nav"!==e.className&&e.parentNode;)"LI"!==e.parentNode.tagName&&"app-sub-sidebar"!==e.parentNode.className||e.parentNode.classList.add("open"),e=e.parentNode}function d(e,n,t){if(e&&e.tagName===n)return e;for(var a=0;e;){if(t<++a)return;if(e.parentNode.tagName===n)return e.parentNode;e=e.parentNode}}e(".sidebar-nav > ul > li ul {\n display: none;\n}\n\n.app-sub-sidebar {\n display: none;\n}\n\n.app-sub-sidebar.open {\n display: block;\n}\n\n.sidebar-nav .open > ul:not(.app-sub-sidebar),\n.sidebar-nav .active:not(.collapse) > ul {\n display: block;\n}\n\n/* 抖动 */\n.sidebar-nav li.open:not(.collapse) > ul {\n display: block;\n}\n\n.active + ul.app-sub-sidebar {\n display: block;\n}\n"),document.addEventListener("scroll",n);e("@media screen and (max-width: 768px) {\n /* 移动端适配 */\n .markdown-section {\n max-width: none;\n padding: 16px;\n }\n /* 改变原来按钮热区大小 */\n .sidebar-toggle {\n padding: 0 0 10px 10px;\n }\n /* my pin */\n .sidebar-pin {\n appearance: none;\n outline: none;\n position: fixed;\n bottom: 0;\n border: none;\n width: 40px;\n height: 40px;\n background: transparent;\n }\n}\n");var r,c="DOCSIFY_SIDEBAR_PIN_FLAG";function l(){var e="true"===(e=localStorage.getItem(c));localStorage.setItem(c,!e),e?(document.querySelector(".sidebar").style.transform="translateX(0)",document.querySelector(".content").style.transform="translateX(0)"):(document.querySelector(".sidebar").style.transform="translateX(300px)",document.querySelector(".content").style.transform="translateX(300px)")}768<document.documentElement.clientWidth||(localStorage.setItem(c,!1),(r=document.createElement("button")).classList.add("sidebar-pin"),r.onclick=l,document.body.append(r),window.addEventListener("load",function(){var n=document.querySelector(".content");document.body.onclick=n.onclick=function(e){e.target!==document.body&&e.currentTarget!==n||"true"===localStorage.getItem(c)&&l()}})),function(){if(window.$docsify){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];$docsify.plugins=n.concat($docsify.plugins||[])}else console.error("这是一个docsify插件,请先引用docsify库!")}(function(e,n){e.doneEach(function(e,n){var t=s();i(t),document.querySelectorAll(".sidebar-nav li").forEach(function(e){e.querySelector("ul:not(.app-sub-sidebar)")?e.classList.add("folder"):e.classList.add("file")}),function n(e,t){e&&e.childNodes&&e.childNodes.forEach(function(e){e.classList&&e.classList.contains("folder")&&(e.classList.add("level-".concat(t)),window.$docsify&&window.$docsify.sidebarDisplayLevel&&"number"==typeof window.$docsify.sidebarDisplayLevel&&t<=window.$docsify.sidebarDisplayLevel&&e.classList.add("open"),e&&1<e.childNodes.length&&n(e.childNodes[1],t+1))})}(document.querySelector(".sidebar-nav > ul"),1),a(t),n(e)}),e.ready(function(){document.querySelector(".sidebar-nav").addEventListener("click",o)})})});
|
||||||
1
docsify.js
Normal file
1
docsify.js
Normal file
File diff suppressed because one or more lines are too long
48
index.html
Normal file
48
index.html
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Document</title>
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
||||||
|
<meta name="docsify" content="docsify">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
|
||||||
|
<!--<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify@4/lib/themes/vue.css">-->
|
||||||
|
<link rel="stylesheet" href="./vue.css">
|
||||||
|
<!-- <div id="app">加载中</div> -->
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="app"></div>
|
||||||
|
<script>
|
||||||
|
window.$docsify = {
|
||||||
|
name: 'Messenger SDK 使用文档',
|
||||||
|
repo: '',
|
||||||
|
mergeNavbar: true,
|
||||||
|
loadSidebar: 'list.md',
|
||||||
|
loadNavbar: true,
|
||||||
|
auto2top: true,
|
||||||
|
topMargin: 90,
|
||||||
|
subMaxLevel: 2,
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<!-- Docsify v4 -->
|
||||||
|
<!--<script src="//cdn.jsdelivr.net/npm/docsify@4"></script>
|
||||||
|
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-lua.js"></script>-->
|
||||||
|
<!--<script src="./docsify-sidebar-collapse.min.js"></script>-->
|
||||||
|
<!--<link rel="stylesheet" href="./sidebar.min.css"/>-->
|
||||||
|
<!-- 在 <script> 标签之前导入样式文件 -->
|
||||||
|
<!-- 代码高亮 -->
|
||||||
|
<!--<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-c.js"></script>
|
||||||
|
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-cpp.js"></script>-->
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/prismjs/themes/prism.css">
|
||||||
|
<script src="//cdn.jsdelivr.net/npm/docsify/lib/plugins/external-script.js"></script>
|
||||||
|
<script src="./docsify-copy-code.js"></script>
|
||||||
|
<script src="./docsify-pagination.min.js"></script>
|
||||||
|
<script src="./search.min.js"></script>
|
||||||
|
<script src="./docsify.js"></script>
|
||||||
|
<script src="./prism-lua.js"></script>
|
||||||
|
<script src="./prism-c.js"></script>
|
||||||
|
<script src="./prism-cpp.js"></script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
4
list.md
Normal file
4
list.md
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
* 文档
|
||||||
|
* [首页](README.md)
|
||||||
|
* [快速入门](doc/entry.md)
|
||||||
|
* [异常处理](doc/error.md)
|
||||||
80
prism-c.js
Normal file
80
prism-c.js
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
Prism.languages.c = Prism.languages.extend('clike', {
|
||||||
|
'comment': {
|
||||||
|
pattern: /\/\/(?:[^\r\n\\]|\\(?:\r\n?|\n|(?![\r\n])))*|\/\*[\s\S]*?(?:\*\/|$)/,
|
||||||
|
greedy: true
|
||||||
|
},
|
||||||
|
'string': {
|
||||||
|
// https://en.cppreference.com/w/c/language/string_literal
|
||||||
|
pattern: /"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"/,
|
||||||
|
greedy: true
|
||||||
|
},
|
||||||
|
'class-name': {
|
||||||
|
pattern: /(\b(?:enum|struct)\s+(?:__attribute__\s*\(\([\s\S]*?\)\)\s*)?)\w+|\b[a-z]\w*_t\b/,
|
||||||
|
lookbehind: true
|
||||||
|
},
|
||||||
|
'keyword': /\b(?:_Alignas|_Alignof|_Atomic|_Bool|_Complex|_Generic|_Imaginary|_Noreturn|_Static_assert|_Thread_local|__attribute__|asm|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|inline|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|typeof|union|unsigned|void|volatile|while)\b/,
|
||||||
|
'function': /\b[a-z_]\w*(?=\s*\()/i,
|
||||||
|
'number': /(?:\b0x(?:[\da-f]+(?:\.[\da-f]*)?|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)[ful]{0,4}/i,
|
||||||
|
'operator': />>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?/
|
||||||
|
});
|
||||||
|
|
||||||
|
Prism.languages.insertBefore('c', 'string', {
|
||||||
|
'char': {
|
||||||
|
// https://en.cppreference.com/w/c/language/character_constant
|
||||||
|
pattern: /'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n]){0,32}'/,
|
||||||
|
greedy: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Prism.languages.insertBefore('c', 'string', {
|
||||||
|
'macro': {
|
||||||
|
// allow for multiline macro definitions
|
||||||
|
// spaces after the # character compile fine with gcc
|
||||||
|
pattern: /(^[\t ]*)#\s*[a-z](?:[^\r\n\\/]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|\\(?:\r\n|[\s\S]))*/im,
|
||||||
|
lookbehind: true,
|
||||||
|
greedy: true,
|
||||||
|
alias: 'property',
|
||||||
|
inside: {
|
||||||
|
'string': [
|
||||||
|
{
|
||||||
|
// highlight the path of the include statement as a string
|
||||||
|
pattern: /^(#\s*include\s*)<[^>]+>/,
|
||||||
|
lookbehind: true
|
||||||
|
},
|
||||||
|
Prism.languages.c['string']
|
||||||
|
],
|
||||||
|
'char': Prism.languages.c['char'],
|
||||||
|
'comment': Prism.languages.c['comment'],
|
||||||
|
'macro-name': [
|
||||||
|
{
|
||||||
|
pattern: /(^#\s*define\s+)\w+\b(?!\()/i,
|
||||||
|
lookbehind: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pattern: /(^#\s*define\s+)\w+\b(?=\()/i,
|
||||||
|
lookbehind: true,
|
||||||
|
alias: 'function'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
// highlight macro directives as keywords
|
||||||
|
'directive': {
|
||||||
|
pattern: /^(#\s*)[a-z]+/,
|
||||||
|
lookbehind: true,
|
||||||
|
alias: 'keyword'
|
||||||
|
},
|
||||||
|
'directive-hash': /^#/,
|
||||||
|
'punctuation': /##|\\(?=[\r\n])/,
|
||||||
|
'expression': {
|
||||||
|
pattern: /\S[\s\S]*/,
|
||||||
|
inside: Prism.languages.c
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Prism.languages.insertBefore('c', 'function', {
|
||||||
|
// highlight predefined macros as constants
|
||||||
|
'constant': /\b(?:EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|__DATE__|__FILE__|__LINE__|__TIMESTAMP__|__TIME__|__func__|stderr|stdin|stdout)\b/
|
||||||
|
});
|
||||||
|
|
||||||
|
delete Prism.languages.c['boolean'];
|
||||||
99
prism-cpp.js
Normal file
99
prism-cpp.js
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
(function (Prism) {
|
||||||
|
|
||||||
|
var keyword = /\b(?:alignas|alignof|asm|auto|bool|break|case|catch|char|char16_t|char32_t|char8_t|class|co_await|co_return|co_yield|compl|concept|const|const_cast|consteval|constexpr|constinit|continue|decltype|default|delete|do|double|dynamic_cast|else|enum|explicit|export|extern|final|float|for|friend|goto|if|import|inline|int|int16_t|int32_t|int64_t|int8_t|long|module|mutable|namespace|new|noexcept|nullptr|operator|override|private|protected|public|register|reinterpret_cast|requires|return|short|signed|sizeof|static|static_assert|static_cast|struct|switch|template|this|thread_local|throw|try|typedef|typeid|typename|uint16_t|uint32_t|uint64_t|uint8_t|union|unsigned|using|virtual|void|volatile|wchar_t|while)\b/;
|
||||||
|
var modName = /\b(?!<keyword>)\w+(?:\s*\.\s*\w+)*\b/.source.replace(/<keyword>/g, function () { return keyword.source; });
|
||||||
|
|
||||||
|
Prism.languages.cpp = Prism.languages.extend('c', {
|
||||||
|
'class-name': [
|
||||||
|
{
|
||||||
|
pattern: RegExp(/(\b(?:class|concept|enum|struct|typename)\s+)(?!<keyword>)\w+/.source
|
||||||
|
.replace(/<keyword>/g, function () { return keyword.source; })),
|
||||||
|
lookbehind: true
|
||||||
|
},
|
||||||
|
// This is intended to capture the class name of method implementations like:
|
||||||
|
// void foo::bar() const {}
|
||||||
|
// However! The `foo` in the above example could also be a namespace, so we only capture the class name if
|
||||||
|
// it starts with an uppercase letter. This approximation should give decent results.
|
||||||
|
/\b[A-Z]\w*(?=\s*::\s*\w+\s*\()/,
|
||||||
|
// This will capture the class name before destructors like:
|
||||||
|
// Foo::~Foo() {}
|
||||||
|
/\b[A-Z_]\w*(?=\s*::\s*~\w+\s*\()/i,
|
||||||
|
// This also intends to capture the class name of method implementations but here the class has template
|
||||||
|
// parameters, so it can't be a namespace (until C++ adds generic namespaces).
|
||||||
|
/\b\w+(?=\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>\s*::\s*\w+\s*\()/
|
||||||
|
],
|
||||||
|
'keyword': keyword,
|
||||||
|
'number': {
|
||||||
|
pattern: /(?:\b0b[01']+|\b0x(?:[\da-f']+(?:\.[\da-f']*)?|\.[\da-f']+)(?:p[+-]?[\d']+)?|(?:\b[\d']+(?:\.[\d']*)?|\B\.[\d']+)(?:e[+-]?[\d']+)?)[ful]{0,4}/i,
|
||||||
|
greedy: true
|
||||||
|
},
|
||||||
|
'operator': />>=?|<<=?|->|--|\+\+|&&|\|\||[?:~]|<=>|[-+*/%&|^!=<>]=?|\b(?:and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/,
|
||||||
|
'boolean': /\b(?:false|true)\b/
|
||||||
|
});
|
||||||
|
|
||||||
|
Prism.languages.insertBefore('cpp', 'string', {
|
||||||
|
'module': {
|
||||||
|
// https://en.cppreference.com/w/cpp/language/modules
|
||||||
|
pattern: RegExp(
|
||||||
|
/(\b(?:import|module)\s+)/.source +
|
||||||
|
'(?:' +
|
||||||
|
// header-name
|
||||||
|
/"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|<[^<>\r\n]*>/.source +
|
||||||
|
'|' +
|
||||||
|
// module name or partition or both
|
||||||
|
/<mod-name>(?:\s*:\s*<mod-name>)?|:\s*<mod-name>/.source.replace(/<mod-name>/g, function () { return modName; }) +
|
||||||
|
')'
|
||||||
|
),
|
||||||
|
lookbehind: true,
|
||||||
|
greedy: true,
|
||||||
|
inside: {
|
||||||
|
'string': /^[<"][\s\S]+/,
|
||||||
|
'operator': /:/,
|
||||||
|
'punctuation': /\./
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'raw-string': {
|
||||||
|
pattern: /R"([^()\\ ]{0,16})\([\s\S]*?\)\1"/,
|
||||||
|
alias: 'string',
|
||||||
|
greedy: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Prism.languages.insertBefore('cpp', 'keyword', {
|
||||||
|
'generic-function': {
|
||||||
|
pattern: /\b(?!operator\b)[a-z_]\w*\s*<(?:[^<>]|<[^<>]*>)*>(?=\s*\()/i,
|
||||||
|
inside: {
|
||||||
|
'function': /^\w+/,
|
||||||
|
'generic': {
|
||||||
|
pattern: /<[\s\S]+/,
|
||||||
|
alias: 'class-name',
|
||||||
|
inside: Prism.languages.cpp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Prism.languages.insertBefore('cpp', 'operator', {
|
||||||
|
'double-colon': {
|
||||||
|
pattern: /::/,
|
||||||
|
alias: 'punctuation'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Prism.languages.insertBefore('cpp', 'class-name', {
|
||||||
|
// the base clause is an optional list of parent classes
|
||||||
|
// https://en.cppreference.com/w/cpp/language/class
|
||||||
|
'base-clause': {
|
||||||
|
pattern: /(\b(?:class|struct)\s+\w+\s*:\s*)[^;{}"'\s]+(?:\s+[^;{}"'\s]+)*(?=\s*[;{])/,
|
||||||
|
lookbehind: true,
|
||||||
|
greedy: true,
|
||||||
|
inside: Prism.languages.extend('cpp', {})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Prism.languages.insertBefore('inside', 'double-colon', {
|
||||||
|
// All untokenized words that are not namespaces should be class names
|
||||||
|
'class-name': /\b[a-z_]\w*\b(?!\s*::)/i
|
||||||
|
}, Prism.languages.cpp['base-clause']);
|
||||||
|
|
||||||
|
}(Prism));
|
||||||
20
prism-lua.js
Normal file
20
prism-lua.js
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
Prism.languages.lua = {
|
||||||
|
'comment': /^#!.+|--(?:\[(=*)\[[\s\S]*?\]\1\]|.*)/m,
|
||||||
|
// \z may be used to skip the following space
|
||||||
|
'string': {
|
||||||
|
pattern: /(["'])(?:(?!\1)[^\\\r\n]|\\z(?:\r\n|\s)|\\(?:\r\n|[^z]))*\1|\[(=*)\[[\s\S]*?\]\2\]/,
|
||||||
|
greedy: true
|
||||||
|
},
|
||||||
|
'number': /\b0x[a-f\d]+(?:\.[a-f\d]*)?(?:p[+-]?\d+)?\b|\b\d+(?:\.\B|(?:\.\d*)?(?:e[+-]?\d+)?\b)|\B\.\d+(?:e[+-]?\d+)?\b/i,
|
||||||
|
'keyword': /\b(?:and|break|do|else|elseif|end|false|for|function|goto|if|in|local|nil|not|or|repeat|return|then|true|until|while)\b/,
|
||||||
|
'function': /(?!\d)\w+(?=\s*(?:[({]))/,
|
||||||
|
'operator': [
|
||||||
|
/[-+*%^&|#]|\/\/?|<[<=]?|>[>=]?|[=~]=?/,
|
||||||
|
{
|
||||||
|
// Match ".." but don't break "..."
|
||||||
|
pattern: /(^|[^.])\.\.(?!\.)/,
|
||||||
|
lookbehind: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
'punctuation': /[\[\](){},;]|\.+|:+/
|
||||||
|
};
|
||||||
1
search.min.js
vendored
Normal file
1
search.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
sidebar.min.css
vendored
Normal file
1
sidebar.min.css
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.sidebar-nav li{position:relative;margin:0;cursor:pointer}.sidebar-nav ul:not(.app-sub-sidebar)>li:not(.file)::before{content:'';display:block;position:absolute;top:11px;left:-12px;height:6px;width:6px;border-right:1px solid #505d6b;border-bottom:1px solid #505d6b;transform:rotate(-45deg);transition:transform .1s}.sidebar-nav ul:not(.app-sub-sidebar)>li.open::before{transform:rotate(45deg)}.sidebar-nav ul:not(.app-sub-sidebar)>li.collapse::before{transform:rotate(-45deg)}
|
||||||
Reference in New Issue
Block a user