MCPcopy
hub / github.com/marimo-team/marimo / getStringContent

Function getStringContent

packages/smart-cells/src/utils/python-ast.ts:113–168  ·  view source on GitHub ↗
(
  node: SyntaxNode,
  code: string,
)

Source from the content-addressed store, hash-verified

111 * @returns The string content, or null if not a string node
112 */
113export function getStringContent(
114 node: SyntaxNode,
115 code: string,
116): string | null {
117 // Handle triple quoted strings
118 if (node.name === "String") {
119 const content = code.slice(node.from, node.to);
120 // Handle r-strings with triple quotes
121 if (content.startsWith('r"""') || content.startsWith("r'''")) {
122 return content.slice(4, -3);
123 }
124 // Handle regular triple quotes
125 if (content.startsWith('"""') || content.startsWith("'''")) {
126 return content.slice(3, -3);
127 }
128 // Handle r-strings with single quotes
129 if (content.startsWith('r"') || content.startsWith("r'")) {
130 return content.slice(2, -1);
131 }
132 // Handle single quoted strings
133 return content.slice(1, -1);
134 }
135
136 // Handle f-strings
137 if (node.name === "FormatString") {
138 const content = code.slice(node.from, node.to);
139 if (content.startsWith('f"""') || content.startsWith("f'''")) {
140 return content.slice(4, -3);
141 }
142 if (content.startsWith('rf"""') || content.startsWith("rf'''")) {
143 return content.slice(5, -3);
144 }
145 if (content.startsWith('fr"""') || content.startsWith("fr'''")) {
146 return content.slice(5, -3);
147 }
148 if (content.startsWith('r"""') || content.startsWith("r'''")) {
149 return content.slice(4, -3);
150 }
151 // Single quotes
152 if (content.startsWith('f"') || content.startsWith("f'")) {
153 return content.slice(2, -1);
154 }
155 if (content.startsWith('rf"') || content.startsWith("rf'")) {
156 return content.slice(3, -1);
157 }
158 if (content.startsWith('fr"') || content.startsWith("fr'")) {
159 return content.slice(3, -1);
160 }
161 if (content.startsWith('r"') || content.startsWith("r'")) {
162 return content.slice(2, -1);
163 }
164 return content.slice(2, -1);
165 }
166
167 return null;
168}
169
170/**

Callers 2

parseSQLStatementFunction · 0.85
python-ast.test.tsFile · 0.85

Calls 1

sliceMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…