fork download
  1. enum SupportedTextSplitterLanguage {
  2. Cpp,
  3. Go,
  4. Java,
  5. Js,
  6. Php,
  7. Proto,
  8. Python,
  9. Rst,
  10. Ruby,
  11. Rust,
  12. Scala,
  13. Swift,
  14. Markdown,
  15. Latex,
  16. Html,
  17. Sol,
  18. }
  19.  
  20. fn get_separators_for_language(language: SupportedTextSplitterLanguage) -> Vec<&'static str> {
  21. match language {
  22. SupportedTextSplitterLanguage::Cpp => vec![
  23. "\nclass ", "\nvoid ", "\nint ", "\nfloat ", "\ndouble ",
  24. "\nif ", "\nfor ", "\nwhile ", "\nswitch ", "\ncase ",
  25. "\n\n", "\n", " ", "",
  26. ],
  27. SupportedTextSplitterLanguage::Go => vec![
  28. "\nfunc ", "\nvar ", "\nconst ", "\ntype ",
  29. "\nif ", "\nfor ", "\nswitch ", "\ncase ",
  30. "\n\n", "\n", " ", "",
  31. ],
  32. SupportedTextSplitterLanguage::Java => vec![
  33. "\nclass ", "\npublic ", "\nprotected ", "\nprivate ", "\nstatic ",
  34. "\nif ", "\nfor ", "\nwhile ", "\nswitch ", "\ncase ",
  35. "\n\n", "\n", " ", "",
  36. ],
  37. SupportedTextSplitterLanguage::Js => vec![
  38. "\nfunction ", "\nconst ", "\nlet ", "\nvar ", "\nclass ",
  39. "\nif ", "\nfor ", "\nwhile ", "\nswitch ", "\ncase ", "\ndefault ",
  40. "\n\n", "\n", " ", "",
  41. ],
  42. SupportedTextSplitterLanguage::Php => vec![
  43. "\nfunction ", "\nclass ",
  44. "\nif ", "\nforeach ", "\nwhile ", "\ndo ", "\nswitch ", "\ncase ",
  45. "\n\n", "\n", " ", "",
  46. ],
  47. SupportedTextSplitterLanguage::Proto => vec![
  48. "\nmessage ", "\nservice ", "\nenum ", "\noption ", "\nimport ", "\nsyntax ",
  49. "\n\n", "\n", " ", "",
  50. ],
  51. SupportedTextSplitterLanguage::Python => vec![
  52. "\nclass ", "\ndef ", "\n\tdef ",
  53. "\n\n", "\n", " ", "",
  54. ],
  55. SupportedTextSplitterLanguage::Rst => vec![
  56. "\n===\n", "\n---\n", "\n***\n", "\n.. ",
  57. "\n\n", "\n", " ", "",
  58. ],
  59. SupportedTextSplitterLanguage::Ruby => vec![
  60. "\ndef ", "\nclass ",
  61. "\nif ", "\nunless ", "\nwhile ", "\nfor ", "\ndo ", "\nbegin ", "\nrescue ",
  62. "\n\n", "\n", " ", "",
  63. ],
  64. SupportedTextSplitterLanguage::Rust => vec![
  65. "\nfn ", "\nconst ", "\nlet ",
  66. "\nif ", "\nwhile ", "\nfor ", "\nloop ", "\nmatch ", "\nconst ",
  67. "\n\n", "\n", " ", "",
  68. ],
  69. SupportedTextSplitterLanguage::Scala => vec![
  70. "\nclass ", "\nobject ",
  71. "\ndef ", "\nval ", "\nvar ",
  72. "\nif ", "\nfor ", "\nwhile ", "\nmatch ", "\ncase ",
  73. "\n\n", "\n", " ", "",
  74. ],
  75. SupportedTextSplitterLanguage::Swift => vec![
  76. "\nfunc ", "\nclass ", "\nstruct ", "\nenum ",
  77. "\nif ", "\nfor ", "\nwhile ", "\ndo ", "\nswitch ", "\ncase ",
  78. "\n\n", "\n", " ", "",
  79. ],
  80. SupportedTextSplitterLanguage::Markdown => vec![
  81. "\n## ", "\n### ", "\n#### ", "\n##### ", "\n###### ",
  82. "```\n\n", "\n\n***\n\n", "\n\n---\n\n", "\n\n___\n\n",
  83. "\n\n", "\n", " ", "",
  84. ],
  85. SupportedTextSplitterLanguage::Latex => vec![
  86. "\n\\chapter{", "\n\\section{", "\n\\subsection{", "\n\\subsubsection{",
  87. "\n\\begin{enumerate}", "\n\\begin{itemize}", "\n\\begin{description}", "\n\\begin{list}", "\n\\begin{quote}", "\n\\begin{quotation}", "\n\\begin{verse}", "\n\\begin{verbatim}",
  88. "\n\\begin{align}", "$$", "$",
  89. "\n\n", "\n", " ", "",
  90. ],
  91. SupportedTextSplitterLanguage::Html => vec![
  92. "<body>", "<div>", "<p>", "<br>", "<li>", "<h1>", "<h2>", "<h3>", "<h4>", "<h5>", "<h6>", "<span>", "<table>", "<tr>", "<td>", "<th>", "<ul>", "<ol>", "<header>", "<footer>", "<nav>",
  93. "<head>", "<style>", "<script>", "<meta>", "<title>",
  94. " ", "",
  95. ],
  96. SupportedTextSplitterLanguage::Sol => vec![
  97. "\npragma ", "\nusing ",
  98. "\ncontract ", "\ninterface ", "\nlibrary ",
  99. "\nconstructor ", "\ntype ", "\nfunction ", "\nevent ", "\nmodifier ", "\nerror ", "\nstruct ", "\nenum ",
  100. "\nif ", "\nfor ", "\nwhile ", "\ndo while ", "\nassembly ",
  101. "\n\n", "\n", " ", "",
  102. ],
  103. }
  104. }
  105.  
  106. fn main() {
  107. let separators = get_separators_for_language(SupportedTextSplitterLanguage::Rust);
  108. for separator in separators {
  109. println!("{}", separator);
  110. }
  111. }
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
fn 

const 

let 

if 

while 

for 

loop 

match 

const