Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am working on a text editor in javascript. I have created the front end and i need to prototype a backend. I need to model the structure of the document using this as hierarchy:

Character , Word , Tag , Document

I am trying to create objects based on this hierarchy.

For example:

Characters are represented a linked list. Word are pointers to the first and last characters. Tags are another linked list of words, and a document is a collection of words and tags.

I am was wondering if anyone has a better suggestion to model these relationships as classes. I receive a character from the keyboard and i need to store this as an object in my document model.

thanks

share|improve this question
    
Could you reword this to identify the problem that you are having editing characters? It would help it fit into the SE format better than asking for various suggestions (which may be equally correct, but not actually fix your problem). –  MichaelT Feb 15 '13 at 17:49
1  
A linked list of characters, for a text editor?!? That easily makes the document take five times as much space as necessary! Nine times on 64 bit machines. Not to mention that many operations will become severely less efficient due to your code going crazy hopping all over memory. Why do you think you need a linked list? –  delnan Feb 15 '13 at 17:51
    
i need to apply styles to characters such as bold and italic. So i thought using individual character objects would be easier to implement than storing words. –  Vinoth Sabanadesan Feb 15 '13 at 18:15
    
I don't understand the diference between your char and word objects. If you need particular formatting for a char, why not specify it on the word object? The char object should be a char, not a linked list. Will you have a linked list of blanks between each word? –  gbianchi Feb 15 '13 at 18:27
1  
I would point out that the fair chunk of the Design Patterns is dealing with a word processor and the patterns to make it fit together. –  MichaelT Feb 15 '13 at 18:50
show 3 more comments

1 Answer

You'll want to take a look at Data Structures for Text Sequences, by Charles Crowley.

These 5 notes: 1, 2, 3, 4, 5, have a lot of information on Old School text editor data structures. They may interest you for a number of reasons. First, performance was limited when those were written, so they may end up as very high speed structures today. Second, programs were a lot harder to write, so the very simplicity may appeal to you if you're just trying to get a working back end.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.