Skip to content

Commit

Permalink
Add cell contents in quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisWhisker committed Apr 21, 2024
1 parent 3089b70 commit 4bafd80
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
36 changes: 34 additions & 2 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ function loadCSV(url) {
// Parse the CSV data
const rows = data.split("\n");
for (const row of rows) {
const columns = row.split(",").filter(column => column !== "");
// Split the row by commas while handling quoted cells
const columns = splitCSVRow(row);
if (columns.length === 0) continue; // Skip empty rows

const category = columns[0]; // Get the category name from the first column
const words = columns.slice(1).map(word => word.trim()); // Get the words for the category

Expand All @@ -39,6 +42,35 @@ function loadCSV(url) {
});
}

// Function to split a CSV row into columns, handling quoted cells containing commas
function splitCSVRow(row) {
const columns = [];
let currentColumn = ''; // Buffer for the current column being processed
let insideQuotes = false;

for (let i = 0; i < row.length; i++) {
const char = row[i];
if (char === '"') {
// Toggle insideQuotes when encountering a quote
insideQuotes = !insideQuotes;
} else if (char === ',' && !insideQuotes) {
// Push the current column to columns array when encountering a comma outside quotes
columns.push(currentColumn);
currentColumn = ''; // Reset currentColumn buffer
} else {
// Append the character to the current column buffer
currentColumn += char;
}
}

// Push the last column to columns array
columns.push(currentColumn);

return columns;
}



function createButtons(strings) {
// Check if buttonContainer exists
if (!buttonContainer) {
Expand Down Expand Up @@ -94,7 +126,7 @@ function search(query) {
for (const category in wordCategories) {
console.log("Adding all words in category: " + category + " to results.");
for (const word of wordCategories[category]) {
console.log("Adding word: " + word + " to results.");
console.log("\tAdding word: \"" + word + "\" to results.");
results.push(word);
}
}
Expand Down
2 changes: 1 addition & 1 deletion words.csv
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ Body Parts,head,stomach,back,arms,legs,rump,tail,core,fingers,,,,,,,,,,,,,,,,,,,
Affinities,physical,standard,striking,slashing,piercing,fire,lightning,magic,holy,poison,toxic,scarlet rot,blood loss,frost,sleep,madness,death,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Concepts,life,Death,light,dark,stars,fire,Order,chaos,joy,wrath,suffering,sadness,comfort,bliss,misfortune,good fortune,bad luck,hope,despair,victory,defeat,research,faith,abundance,rot,loyalty,injustice,secret,opportunity,pickle,clue,friendship,love,bravery,vigor,fortitude,confidence,distracted,unguarded,introspection,regret,resignation,futility,on the brink,betrayal,revenge,destruction,recklessness,calmness,vigilance,tranquility,sound,tears,sleep,depths,dregs,fear,sacrifice,ruin
Phrases,good luck,look carefully,listen carefully,think carefully,well done,I did it!,I've failed...,here!,not here!,don't you dare!,do it!,I can't take this...,don't think,so lonely...,here again...,just getting started,stay calm,keep moving,turn back,give up,don't give up,help me...,I don't believe it...,too high up,I want to go home...,it's like a dream...,seems familiar...,beautiful...,you don't have the right,are you ready?,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Conjunctions,and then,or,but,therefore,in short,except,by the way,so to speak,all the more,",",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Conjunctions,and then,or,but,therefore,in short,except,by the way,so to speak,all the more,",",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

0 comments on commit 4bafd80

Please sign in to comment.