SlideShare a Scribd company logo

What you forgot from your Computer Science Degree

An interesting -- possibly over engineered -- way to convert all occurrences of HTML escape characters into their Unicode equivalent on I

1 of 14
Download to read offline
What you forgot from your
Computer Science
Degree
Stephen Darlington
Wandle Software Limited
Okay, not all of it.
Requirements
•

Parse a string. Convert all occurrences of HTML
escape characters into their Unicode equivalent

•

"If you see '&lt;' convert it to '<'"
How Google Did It
static HTMLEscapeMap gAsciiHTMLEscapeMap[] = {
// A.2.2. Special characters
{ @"&quot;", 34 },
{ @"&amp;", 38 },
{ @"&apos;", 39 },
{ @"&lt;", 60 },
...
{ @"&hearts;", 9829 },
{ @"&diams;", 9830 }
};
https://code.google.com/p/google-toolbox-for-mac/source/browse/trunk/Foundation/GTMNSString
%2BHTML.m
How Google Did It
for (unsigned i = 0; i < sizeof(gAsciiHTMLEscapeMap) /
sizeof(HTMLEscapeMap); ++i) {
if ([escapeString
isEqualToString:gAsciiHTMLEscapeMap[i].escapeSequence]) {
[finalString replaceCharactersInRange:escapeRange withString:
[NSString stringWithCharacters:&gAsciiHTMLEscapeMap[i].uchar length:1]];
break;
}
}
Yuck
Ad

Recommended

SQL Tuning Overview
SQL Tuning OverviewSQL Tuning Overview
SQL Tuning OverviewKai Liu
 
Surfacing External Data Through Magnolia
Surfacing External Data Through MagnoliaSurfacing External Data Through Magnolia
Surfacing External Data Through MagnoliaSeanMcTex
 
Rails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity PresentationRails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity Presentationrailsconf
 
Asp 4-razor-introduction of view engine
Asp 4-razor-introduction of view engineAsp 4-razor-introduction of view engine
Asp 4-razor-introduction of view engineFajar Baskoro
 

More Related Content

Viewers also liked

Informed_Consent_Overview
Informed_Consent_OverviewInformed_Consent_Overview
Informed_Consent_OverviewSusan Stoltzfus
 
i-10 Hospitality Company Presentation
i-10 Hospitality Company Presentationi-10 Hospitality Company Presentation
i-10 Hospitality Company PresentationI-10 Hospitality, LLC
 
Updated Presentation1 brooks
Updated Presentation1 brooksUpdated Presentation1 brooks
Updated Presentation1 brooksmbrooks240
 
Presentation 1 Brooks
Presentation 1 BrooksPresentation 1 Brooks
Presentation 1 Brooksmbrooks240
 
презентация маркетинг бюро
презентация маркетинг бюропрезентация маркетинг бюро
презентация маркетинг бюроguseva_mb_buro
 
Community Winter 2006 Web
Community Winter 2006 WebCommunity Winter 2006 Web
Community Winter 2006 WebSusan Stoltzfus
 
Benefit innovators actuarial services and healthcare reform
Benefit innovators actuarial services and healthcare reformBenefit innovators actuarial services and healthcare reform
Benefit innovators actuarial services and healthcare reformBrad Vernon
 
As tic na escola 2013-14
As tic na escola   2013-14As tic na escola   2013-14
As tic na escola 2013-14cfrvigotic2
 
Mala Jewish Synagogue, Cochin
Mala Jewish Synagogue, CochinMala Jewish Synagogue, Cochin
Mala Jewish Synagogue, Cochinwlts
 
Презентация "Маркетинг-Бюро"
Презентация "Маркетинг-Бюро"Презентация "Маркетинг-Бюро"
Презентация "Маркетинг-Бюро"guseva_mb_buro
 
How to Make an Effective PowerPoint Presentation
How to Make an Effective PowerPoint PresentationHow to Make an Effective PowerPoint Presentation
How to Make an Effective PowerPoint Presentationmbrooks240
 
Familiarity Breeds Contempt (Or why all APIs suck, even yours.)
Familiarity Breeds Contempt (Or why all APIs suck, even yours.)Familiarity Breeds Contempt (Or why all APIs suck, even yours.)
Familiarity Breeds Contempt (Or why all APIs suck, even yours.)Stephen Darlington
 

Viewers also liked (12)

Informed_Consent_Overview
Informed_Consent_OverviewInformed_Consent_Overview
Informed_Consent_Overview
 
i-10 Hospitality Company Presentation
i-10 Hospitality Company Presentationi-10 Hospitality Company Presentation
i-10 Hospitality Company Presentation
 
Updated Presentation1 brooks
Updated Presentation1 brooksUpdated Presentation1 brooks
Updated Presentation1 brooks
 
Presentation 1 Brooks
Presentation 1 BrooksPresentation 1 Brooks
Presentation 1 Brooks
 
презентация маркетинг бюро
презентация маркетинг бюропрезентация маркетинг бюро
презентация маркетинг бюро
 
Community Winter 2006 Web
Community Winter 2006 WebCommunity Winter 2006 Web
Community Winter 2006 Web
 
Benefit innovators actuarial services and healthcare reform
Benefit innovators actuarial services and healthcare reformBenefit innovators actuarial services and healthcare reform
Benefit innovators actuarial services and healthcare reform
 
As tic na escola 2013-14
As tic na escola   2013-14As tic na escola   2013-14
As tic na escola 2013-14
 
Mala Jewish Synagogue, Cochin
Mala Jewish Synagogue, CochinMala Jewish Synagogue, Cochin
Mala Jewish Synagogue, Cochin
 
Презентация "Маркетинг-Бюро"
Презентация "Маркетинг-Бюро"Презентация "Маркетинг-Бюро"
Презентация "Маркетинг-Бюро"
 
How to Make an Effective PowerPoint Presentation
How to Make an Effective PowerPoint PresentationHow to Make an Effective PowerPoint Presentation
How to Make an Effective PowerPoint Presentation
 
Familiarity Breeds Contempt (Or why all APIs suck, even yours.)
Familiarity Breeds Contempt (Or why all APIs suck, even yours.)Familiarity Breeds Contempt (Or why all APIs suck, even yours.)
Familiarity Breeds Contempt (Or why all APIs suck, even yours.)
 

Similar to What you forgot from your Computer Science Degree

Scala 3camp 2011
Scala   3camp 2011Scala   3camp 2011
Scala 3camp 2011Scalac
 
Csphtp1 18
Csphtp1 18Csphtp1 18
Csphtp1 18HUST
 
JavaScript and jQuery Fundamentals
JavaScript and jQuery FundamentalsJavaScript and jQuery Fundamentals
JavaScript and jQuery FundamentalsBG Java EE Course
 
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)Carles Farré
 
Interoperable Web Services with JAX-WS
Interoperable Web Services with JAX-WSInteroperable Web Services with JAX-WS
Interoperable Web Services with JAX-WSCarol McDonald
 
Aug Xml Net Forum Dynamics Integration
Aug Xml Net Forum Dynamics IntegrationAug Xml Net Forum Dynamics Integration
Aug Xml Net Forum Dynamics IntegrationMariAnne Woehrle
 
Effecient javascript
Effecient javascriptEffecient javascript
Effecient javascriptmpnkhan
 
Struts2
Struts2Struts2
Struts2yuvalb
 
My First Rails Plugin - Usertext
My First Rails Plugin - UsertextMy First Rails Plugin - Usertext
My First Rails Plugin - Usertextfrankieroberto
 
Kickstarting SItes With a Custom Package
Kickstarting SItes With a Custom PackageKickstarting SItes With a Custom Package
Kickstarting SItes With a Custom PackageJeff Segars
 
49368010 projectreportontraininganddevelopment(1)
49368010 projectreportontraininganddevelopment(1)49368010 projectreportontraininganddevelopment(1)
49368010 projectreportontraininganddevelopment(1)Kritika910
 
Web Security Mistakes: Trusting The Client
Web Security Mistakes: Trusting The ClientWeb Security Mistakes: Trusting The Client
Web Security Mistakes: Trusting The Clientgrutz
 
What's new in Rails 2?
What's new in Rails 2?What's new in Rails 2?
What's new in Rails 2?brynary
 
Embedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for JavaEmbedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for JavaJevgeni Kabanov
 

Similar to What you forgot from your Computer Science Degree (20)

Scala 3camp 2011
Scala   3camp 2011Scala   3camp 2011
Scala 3camp 2011
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Jquery 1
Jquery 1Jquery 1
Jquery 1
 
AngularJS Basics with Example
AngularJS Basics with ExampleAngularJS Basics with Example
AngularJS Basics with Example
 
Csphtp1 18
Csphtp1 18Csphtp1 18
Csphtp1 18
 
JavaScript and jQuery Fundamentals
JavaScript and jQuery FundamentalsJavaScript and jQuery Fundamentals
JavaScript and jQuery Fundamentals
 
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
 
Interoperable Web Services with JAX-WS
Interoperable Web Services with JAX-WSInteroperable Web Services with JAX-WS
Interoperable Web Services with JAX-WS
 
Aug Xml Net Forum Dynamics Integration
Aug Xml Net Forum Dynamics IntegrationAug Xml Net Forum Dynamics Integration
Aug Xml Net Forum Dynamics Integration
 
Effecient javascript
Effecient javascriptEffecient javascript
Effecient javascript
 
Struts2
Struts2Struts2
Struts2
 
My First Rails Plugin - Usertext
My First Rails Plugin - UsertextMy First Rails Plugin - Usertext
My First Rails Plugin - Usertext
 
Kickstarting SItes With a Custom Package
Kickstarting SItes With a Custom PackageKickstarting SItes With a Custom Package
Kickstarting SItes With a Custom Package
 
49368010 projectreportontraininganddevelopment(1)
49368010 projectreportontraininganddevelopment(1)49368010 projectreportontraininganddevelopment(1)
49368010 projectreportontraininganddevelopment(1)
 
Web Security Mistakes: Trusting The Client
Web Security Mistakes: Trusting The ClientWeb Security Mistakes: Trusting The Client
Web Security Mistakes: Trusting The Client
 
What's new in Rails 2?
What's new in Rails 2?What's new in Rails 2?
What's new in Rails 2?
 
Embedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for JavaEmbedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for Java
 
SQL -PHP Tutorial
SQL -PHP TutorialSQL -PHP Tutorial
SQL -PHP Tutorial
 
Ajax ons2
Ajax ons2Ajax ons2
Ajax ons2
 
All things that are not code
All things that are not codeAll things that are not code
All things that are not code
 

Recently uploaded

ASTRAZENECA. Knowledge Graphs Powering a Fast-moving Global Life Sciences Org...
ASTRAZENECA. Knowledge Graphs Powering a Fast-moving Global Life Sciences Org...ASTRAZENECA. Knowledge Graphs Powering a Fast-moving Global Life Sciences Org...
ASTRAZENECA. Knowledge Graphs Powering a Fast-moving Global Life Sciences Org...Neo4j
 
"Testing of Helm Charts or There and Back Again", Yura Rochniak
"Testing of Helm Charts or There and Back Again", Yura Rochniak"Testing of Helm Charts or There and Back Again", Yura Rochniak
"Testing of Helm Charts or There and Back Again", Yura RochniakFwdays
 
The Art of the Possible with Graph by Dr Jim Webber Neo4j.pptx
The Art of the Possible with Graph by Dr Jim Webber Neo4j.pptxThe Art of the Possible with Graph by Dr Jim Webber Neo4j.pptx
The Art of the Possible with Graph by Dr Jim Webber Neo4j.pptxNeo4j
 
Act Like an Owner, Challenge Like a VC by former CPO, Tripadvisor
Act Like an Owner,  Challenge Like a VC by former CPO, TripadvisorAct Like an Owner,  Challenge Like a VC by former CPO, Tripadvisor
Act Like an Owner, Challenge Like a VC by former CPO, TripadvisorProduct School
 
"How we created an SRE team in Temabit as a part of FOZZY Group in conditions...
"How we created an SRE team in Temabit as a part of FOZZY Group in conditions..."How we created an SRE team in Temabit as a part of FOZZY Group in conditions...
"How we created an SRE team in Temabit as a part of FOZZY Group in conditions...Fwdays
 
Bit N Build Poland
Bit N Build PolandBit N Build Poland
Bit N Build PolandGDSC PJATK
 
"DevOps Practisting Platform on EKS with Karpenter autoscaling", Dmytro Kozhevin
"DevOps Practisting Platform on EKS with Karpenter autoscaling", Dmytro Kozhevin"DevOps Practisting Platform on EKS with Karpenter autoscaling", Dmytro Kozhevin
"DevOps Practisting Platform on EKS with Karpenter autoscaling", Dmytro KozhevinFwdays
 
Are Human-generated Demonstrations Necessary for In-context Learning?
Are Human-generated Demonstrations Necessary for In-context Learning?Are Human-generated Demonstrations Necessary for In-context Learning?
Are Human-generated Demonstrations Necessary for In-context Learning?MENGSAYLOEM1
 
AI Act & Standardization: UNINFO involvement
AI Act & Standardization: UNINFO involvementAI Act & Standardization: UNINFO involvement
AI Act & Standardization: UNINFO involvementMimmo Squillace
 
How we think about an advisor tech stack
How we think about an advisor tech stackHow we think about an advisor tech stack
How we think about an advisor tech stackSummit
 
Progress Report: Ministry of IT under Dr. Umar Saif Aug 23-Feb'24
Progress Report: Ministry of IT under Dr. Umar Saif Aug 23-Feb'24Progress Report: Ministry of IT under Dr. Umar Saif Aug 23-Feb'24
Progress Report: Ministry of IT under Dr. Umar Saif Aug 23-Feb'24Umar Saif
 
How to write an effective Cyber Incident Response Plan
How to write an effective Cyber Incident Response PlanHow to write an effective Cyber Incident Response Plan
How to write an effective Cyber Incident Response PlanDatabarracks
 
AI MODELS USAGE IN FINTECH PRODUCTS: PM APPROACH & BEST PRACTICES by Kasthuri...
AI MODELS USAGE IN FINTECH PRODUCTS: PM APPROACH & BEST PRACTICES by Kasthuri...AI MODELS USAGE IN FINTECH PRODUCTS: PM APPROACH & BEST PRACTICES by Kasthuri...
AI MODELS USAGE IN FINTECH PRODUCTS: PM APPROACH & BEST PRACTICES by Kasthuri...ISPMAIndia
 
Confoo 2024 Gettings started with OpenAI and data science
Confoo 2024 Gettings started with OpenAI and data scienceConfoo 2024 Gettings started with OpenAI and data science
Confoo 2024 Gettings started with OpenAI and data scienceSusan Ibach
 
Introducing the New FME Community Webinar - Feb 21, 2024 (2).pdf
Introducing the New FME Community Webinar - Feb 21, 2024 (2).pdfIntroducing the New FME Community Webinar - Feb 21, 2024 (2).pdf
Introducing the New FME Community Webinar - Feb 21, 2024 (2).pdfSafe Software
 
"Platform Engineering with Development Containers", Igor Fesenko
"Platform Engineering with Development Containers", Igor Fesenko"Platform Engineering with Development Containers", Igor Fesenko
"Platform Engineering with Development Containers", Igor FesenkoFwdays
 
How AI and ChatGPT are changing cybersecurity forever.pptx
How AI and ChatGPT are changing cybersecurity forever.pptxHow AI and ChatGPT are changing cybersecurity forever.pptx
How AI and ChatGPT are changing cybersecurity forever.pptxInfosec
 
LF Energy Webinar: Introduction to TROLIE
LF Energy Webinar: Introduction to TROLIELF Energy Webinar: Introduction to TROLIE
LF Energy Webinar: Introduction to TROLIEDanBrown980551
 
Enhancing Productivity and Insight A Tour of JDK Tools Progress Beyond Java 17
Enhancing Productivity and Insight  A Tour of JDK Tools Progress Beyond Java 17Enhancing Productivity and Insight  A Tour of JDK Tools Progress Beyond Java 17
Enhancing Productivity and Insight A Tour of JDK Tools Progress Beyond Java 17Ana-Maria Mihalceanu
 
"Running Open-Source LLM models on Kubernetes", Volodymyr Tsap
"Running Open-Source LLM models on Kubernetes",  Volodymyr Tsap"Running Open-Source LLM models on Kubernetes",  Volodymyr Tsap
"Running Open-Source LLM models on Kubernetes", Volodymyr TsapFwdays
 

Recently uploaded (20)

ASTRAZENECA. Knowledge Graphs Powering a Fast-moving Global Life Sciences Org...
ASTRAZENECA. Knowledge Graphs Powering a Fast-moving Global Life Sciences Org...ASTRAZENECA. Knowledge Graphs Powering a Fast-moving Global Life Sciences Org...
ASTRAZENECA. Knowledge Graphs Powering a Fast-moving Global Life Sciences Org...
 
"Testing of Helm Charts or There and Back Again", Yura Rochniak
"Testing of Helm Charts or There and Back Again", Yura Rochniak"Testing of Helm Charts or There and Back Again", Yura Rochniak
"Testing of Helm Charts or There and Back Again", Yura Rochniak
 
The Art of the Possible with Graph by Dr Jim Webber Neo4j.pptx
The Art of the Possible with Graph by Dr Jim Webber Neo4j.pptxThe Art of the Possible with Graph by Dr Jim Webber Neo4j.pptx
The Art of the Possible with Graph by Dr Jim Webber Neo4j.pptx
 
Act Like an Owner, Challenge Like a VC by former CPO, Tripadvisor
Act Like an Owner,  Challenge Like a VC by former CPO, TripadvisorAct Like an Owner,  Challenge Like a VC by former CPO, Tripadvisor
Act Like an Owner, Challenge Like a VC by former CPO, Tripadvisor
 
"How we created an SRE team in Temabit as a part of FOZZY Group in conditions...
"How we created an SRE team in Temabit as a part of FOZZY Group in conditions..."How we created an SRE team in Temabit as a part of FOZZY Group in conditions...
"How we created an SRE team in Temabit as a part of FOZZY Group in conditions...
 
Bit N Build Poland
Bit N Build PolandBit N Build Poland
Bit N Build Poland
 
"DevOps Practisting Platform on EKS with Karpenter autoscaling", Dmytro Kozhevin
"DevOps Practisting Platform on EKS with Karpenter autoscaling", Dmytro Kozhevin"DevOps Practisting Platform on EKS with Karpenter autoscaling", Dmytro Kozhevin
"DevOps Practisting Platform on EKS with Karpenter autoscaling", Dmytro Kozhevin
 
Are Human-generated Demonstrations Necessary for In-context Learning?
Are Human-generated Demonstrations Necessary for In-context Learning?Are Human-generated Demonstrations Necessary for In-context Learning?
Are Human-generated Demonstrations Necessary for In-context Learning?
 
AI Act & Standardization: UNINFO involvement
AI Act & Standardization: UNINFO involvementAI Act & Standardization: UNINFO involvement
AI Act & Standardization: UNINFO involvement
 
How we think about an advisor tech stack
How we think about an advisor tech stackHow we think about an advisor tech stack
How we think about an advisor tech stack
 
Progress Report: Ministry of IT under Dr. Umar Saif Aug 23-Feb'24
Progress Report: Ministry of IT under Dr. Umar Saif Aug 23-Feb'24Progress Report: Ministry of IT under Dr. Umar Saif Aug 23-Feb'24
Progress Report: Ministry of IT under Dr. Umar Saif Aug 23-Feb'24
 
How to write an effective Cyber Incident Response Plan
How to write an effective Cyber Incident Response PlanHow to write an effective Cyber Incident Response Plan
How to write an effective Cyber Incident Response Plan
 
AI MODELS USAGE IN FINTECH PRODUCTS: PM APPROACH & BEST PRACTICES by Kasthuri...
AI MODELS USAGE IN FINTECH PRODUCTS: PM APPROACH & BEST PRACTICES by Kasthuri...AI MODELS USAGE IN FINTECH PRODUCTS: PM APPROACH & BEST PRACTICES by Kasthuri...
AI MODELS USAGE IN FINTECH PRODUCTS: PM APPROACH & BEST PRACTICES by Kasthuri...
 
Confoo 2024 Gettings started with OpenAI and data science
Confoo 2024 Gettings started with OpenAI and data scienceConfoo 2024 Gettings started with OpenAI and data science
Confoo 2024 Gettings started with OpenAI and data science
 
Introducing the New FME Community Webinar - Feb 21, 2024 (2).pdf
Introducing the New FME Community Webinar - Feb 21, 2024 (2).pdfIntroducing the New FME Community Webinar - Feb 21, 2024 (2).pdf
Introducing the New FME Community Webinar - Feb 21, 2024 (2).pdf
 
"Platform Engineering with Development Containers", Igor Fesenko
"Platform Engineering with Development Containers", Igor Fesenko"Platform Engineering with Development Containers", Igor Fesenko
"Platform Engineering with Development Containers", Igor Fesenko
 
How AI and ChatGPT are changing cybersecurity forever.pptx
How AI and ChatGPT are changing cybersecurity forever.pptxHow AI and ChatGPT are changing cybersecurity forever.pptx
How AI and ChatGPT are changing cybersecurity forever.pptx
 
LF Energy Webinar: Introduction to TROLIE
LF Energy Webinar: Introduction to TROLIELF Energy Webinar: Introduction to TROLIE
LF Energy Webinar: Introduction to TROLIE
 
Enhancing Productivity and Insight A Tour of JDK Tools Progress Beyond Java 17
Enhancing Productivity and Insight  A Tour of JDK Tools Progress Beyond Java 17Enhancing Productivity and Insight  A Tour of JDK Tools Progress Beyond Java 17
Enhancing Productivity and Insight A Tour of JDK Tools Progress Beyond Java 17
 
"Running Open-Source LLM models on Kubernetes", Volodymyr Tsap
"Running Open-Source LLM models on Kubernetes",  Volodymyr Tsap"Running Open-Source LLM models on Kubernetes",  Volodymyr Tsap
"Running Open-Source LLM models on Kubernetes", Volodymyr Tsap
 

What you forgot from your Computer Science Degree

  • 1. What you forgot from your Computer Science Degree Stephen Darlington Wandle Software Limited
  • 2. Okay, not all of it.
  • 3. Requirements • Parse a string. Convert all occurrences of HTML escape characters into their Unicode equivalent • "If you see '&lt;' convert it to '<'"
  • 4. How Google Did It static HTMLEscapeMap gAsciiHTMLEscapeMap[] = { // A.2.2. Special characters { @"&quot;", 34 }, { @"&amp;", 38 }, { @"&apos;", 39 }, { @"&lt;", 60 }, ... { @"&hearts;", 9829 }, { @"&diams;", 9830 } }; https://code.google.com/p/google-toolbox-for-mac/source/browse/trunk/Foundation/GTMNSString %2BHTML.m
  • 5. How Google Did It for (unsigned i = 0; i < sizeof(gAsciiHTMLEscapeMap) / sizeof(HTMLEscapeMap); ++i) { if ([escapeString isEqualToString:gAsciiHTMLEscapeMap[i].escapeSequence]) { [finalString replaceCharactersInRange:escapeRange withString: [NSString stringWithCharacters:&gAsciiHTMLEscapeMap[i].uchar length:1]]; break; } }
  • 7. “flex is a tool for generating scanners. A scanner is a program which recognizes lexical patterns in text. The flex program [looks for a] description of a scanner to generate. The description is in the form of pairs of regular expressions and C code, called rules. flex generates as output a C source file” Lexical Analysis With Flex Introduction http://flex.sourceforge.net/manual/Introduction.html#Introduction
  • 8. Lexer Description &amp; { return WSL_ENTITY_amp; } &gt; { return WSL_ENTITY_gt; } &lt; { return WSL_ENTITY_lt; } &quot; { return WSL_ENTITY_quot; } &apos; { return WSL_ENTITY_apos; } &AElig; { return WSL_ENTITY_AElig; } ... &#[0-9]+; { return WSL_ENTITY_NUMBER; } [^&]+ { return WSL_ENTITY_NOMATCH; } . { return WSL_ENTITIY_NOMATCH; }
  • 9. Constants #define WSL_ENTITY_NOMATCH -1 #define WSL_ENTITY_NUMBER -2 #define WSL_ENTITY_amp 38 // # ampersand #define WSL_ENTITY_gt 62 // # greater than #define WSL_ENTITY_lt 60 // # less than #define WSL_ENTITY_quot 34 // # double quote ...
  • 10. Main loop while ((expression = WSLlex(scanner))) { switch (expression) { case WSL_ENTITY_NOMATCH: [output appendFormat:@"%@", [NSString stringWithCString:WSLget_text(scanner) encoding:NSISOLatin1StringEncoding]]; break; case WSL_ENTITY_NUMBER: expression = atoi(&WSLget_text(scanner)[2]); // fall through so expression is added to string default: [output appendFormat:@"%C", (unsigned short) expression]; break; } }
  • 12. Benefits • Right tool for the right job • Consistent performance • Xcode knows about Flex (with some caveats) so simple to integrate • Flex has various flags to optimise performance, for example -Cf is much faster but uses lots more memory
  • 13. Further information • WSLHTMLEntities is on GitHub (https://github.com/sdarlington/WSLHTMLEntities ) • Flex documentation (http://flex.sourceforge.net/manual/) • "Introduction to Compiling Techniques," J P Bennett
  • 14. Stephen Darlington Wandle Software Limited @sdarlington @wandlesoftware http://www.zx81.org.uk/ http://www.wandlesoftware.com/ Apps: Yummy / www.cut / Rootn Tootn / CameraGPS