@@ -186,8 +186,7 @@ function syncTableToArrayReOrdered (table, things, createNewRow) {
186186
187187 for ( let g = 0 ; g < things . length ; g ++ ) {
188188 var thing = things [ g ]
189- if ( g >= table . children . length ) {
190- // table needs extending
189+ if ( g >= table . children . length ) { // table needs extending
191190 const newRow = createNewRow ( thing )
192191 newRow . subject = thing
193192 table . appendChild ( newRow )
@@ -413,13 +412,15 @@ function shortName (uri) {
413412 for ( const ns in this . prefixes ) {
414413 namespaces [ this . prefixes [ ns ] ] = ns // reverse index
415414 }
416-
415+ let pok
417416 const canUse = function canUse ( pp ) {
418417 // if (!__Serializer.prototype.validPrefix.test(pp)) return false; // bad format
419- return pp === 'ns'
418+ if ( pp === 'ns' ) return false // boring
420419 // if (pp in this.namespaces) return false; // already used
421420 // this.prefixes[uri] = pp;
422421 // this.namespaces[pp] = uri;
422+ pok = pp
423+ return true
423424 }
424425
425426 let i
@@ -434,14 +435,13 @@ function shortName (uri) {
434435 else break
435436 }
436437 p = p . slice ( 0 , i )
437- if ( p . length < 6 && canUse ( p ) ) {
438- return p
439- } else {
440- for ( let j = 0 ; j < 6 ; j ++ ) {
441- if ( canUse ( p . slice ( 0 , j ) ) ) return p . slice ( 0 , j )
442- }
443- }
444- for ( i = 0 ; ; i ++ ) if ( canUse ( p . slice ( 0 , 3 ) + i ) ) return p . slice ( 0 , 3 ) + i
438+ if ( p . length < 6 && canUse ( p ) ) return pok // exact i sbest
439+ if ( canUse ( p . slice ( 0 , 3 ) ) ) return pok
440+ if ( canUse ( p . slice ( 0 , 2 ) ) ) return pok
441+ if ( canUse ( p . slice ( 0 , 4 ) ) ) return pok
442+ if ( canUse ( p . slice ( 0 , 1 ) ) ) return pok
443+ if ( canUse ( p . slice ( 0 , 5 ) ) ) return pok
444+ for ( i = 0 ; ; i ++ ) if ( canUse ( p . slice ( 0 , 3 ) + i ) ) return pok
445445 }
446446}
447447
@@ -499,59 +499,20 @@ function labelWithOntology (x, initialCap) {
499499//
500500// @returns string
501501//
502-
503- function decodeAsciiPoints ( s ) {
504- for ( var i = s . length - 3 ; i > 0 ; i -- ) {
505- const hex = '0123456789abcefABCDEF' // The while upacks multiple layers of encoding
506- while (
507- s [ i ] === '%' &&
508- hex . indexOf ( s [ i + 1 ] ) >= 0 &&
509- hex . indexOf ( s [ i + 2 ] ) >= 0
510- ) {
511- s =
512- s . slice ( 0 , i ) +
513- String . fromCharCode ( parseInt ( s . slice ( i + 1 , i + 3 ) , 16 ) ) +
514- s . slice ( i + 3 )
515- }
516- }
517- return s
518- }
519- function trimS ( s ) {
520- if ( s . slice ( - 5 ) === '#this' ) s = s . slice ( 0 , - 5 )
521- else if ( s . slice ( - 3 ) === '#me' ) s = s . slice ( 0 , - 3 )
522- // these were below the hash check. not sure if this makes a difference
523- // but something to test to make sure
524- if ( s . slice ( - 9 ) === '/foaf.rdf' ) s = s . slice ( 0 , - 9 )
525- else if ( s . slice ( - 5 ) === '/foaf' ) s = s . slice ( 0 , - 5 )
526- return s
527- }
528- function getLab1 ( x , kb ) {
529- return (
530- kb . any ( x , UI . ns . link ( 'message' ) ) ||
531- kb . any ( x , UI . ns . vcard ( 'fn' ) ) ||
532- kb . any ( x , UI . ns . foaf ( 'name' ) ) ||
533- kb . any ( x , UI . ns . dct ( 'title' ) ) ||
534- kb . any ( x , UI . ns . dc ( 'title' ) ) ||
535- kb . any ( x , UI . ns . rss ( 'title' ) ) ||
536- kb . any ( x , UI . ns . contact ( 'fullName' ) ) ||
537- kb . any ( x , kb . sym ( 'http://www.w3.org/2001/04/roadmap/org#name' ) ) ||
538- kb . any ( x , UI . ns . cal ( 'summary' ) ) ||
539- kb . any ( x , UI . ns . foaf ( 'nick' ) ) ||
540- kb . any ( x , UI . ns . rdfs ( 'label' ) )
541- )
542- }
543502function label ( x , initialCap ) {
544503 // x is an object
545504 function doCap ( s ) {
546505 // s = s.toString()
547- return initialCap ? s . slice ( 0 , 1 ) . toUpperCase ( ) + s . slice ( 1 ) : s
506+ if ( initialCap ) return s . slice ( 0 , 1 ) . toUpperCase ( ) + s . slice ( 1 )
507+ return s
548508 }
549509 function cleanUp ( s1 ) {
550510 var s2 = ''
551511 if ( s1 . slice ( - 1 ) === '/' ) s1 = s1 . slice ( 0 , - 1 ) // chop trailing slash
552512 for ( var i = 0 ; i < s1 . length ; i ++ ) {
553513 if ( s1 [ i ] === '_' || s1 [ i ] === '-' ) {
554514 s2 += ' '
515+ continue
555516 }
556517 s2 += s1 [ i ]
557518 if (
@@ -581,7 +542,18 @@ function label (x, initialCap) {
581542 // @@ TBD: Add subproperties of rdfs:label
582543
583544 var kb = UI . store
584- var lab1 = getLab1 ( x , kb )
545+ var lab1 =
546+ kb . any ( x , UI . ns . link ( 'message' ) ) ||
547+ kb . any ( x , UI . ns . vcard ( 'fn' ) ) ||
548+ kb . any ( x , UI . ns . foaf ( 'name' ) ) ||
549+ kb . any ( x , UI . ns . dct ( 'title' ) ) ||
550+ kb . any ( x , UI . ns . dc ( 'title' ) ) ||
551+ kb . any ( x , UI . ns . rss ( 'title' ) ) ||
552+ kb . any ( x , UI . ns . contact ( 'fullName' ) ) ||
553+ kb . any ( x , kb . sym ( 'http://www.w3.org/2001/04/roadmap/org#name' ) ) ||
554+ kb . any ( x , UI . ns . cal ( 'summary' ) ) ||
555+ kb . any ( x , UI . ns . foaf ( 'nick' ) ) ||
556+ kb . any ( x , UI . ns . rdfs ( 'label' ) )
585557
586558 if ( lab1 ) {
587559 return doCap ( lab1 . value )
@@ -607,15 +579,28 @@ function label (x, initialCap) {
607579 . join ( '/' ) // If it is properly encoded
608580 } catch ( e ) {
609581 // try individual decoding of ASCII code points
610- s = decodeAsciiPoints ( s )
582+ for ( var i = s . length - 3 ; i > 0 ; i -- ) {
583+ const hex = '0123456789abcefABCDEF' // The while upacks multiple layers of encoding
584+ while (
585+ s [ i ] === '%' &&
586+ hex . indexOf ( s [ i + 1 ] ) >= 0 &&
587+ hex . indexOf ( s [ i + 2 ] ) >= 0
588+ ) {
589+ s =
590+ s . slice ( 0 , i ) +
591+ String . fromCharCode ( parseInt ( s . slice ( i + 1 , i + 3 ) , 16 ) ) +
592+ s . slice ( i + 3 )
593+ }
594+ }
611595 }
612- s = trimS ( )
596+ if ( s . slice ( - 5 ) === '#this' ) s = s . slice ( 0 , - 5 )
597+ else if ( s . slice ( - 3 ) === '#me' ) s = s . slice ( 0 , - 3 )
613598
614599 var hash = s . indexOf ( '#' )
615600 if ( hash >= 0 ) return cleanUp ( s . slice ( hash + 1 ) )
616601
617- /* put this in trimS function if (s.slice(-9) === '/foaf.rdf') s = s.slice(0, -9)
618- else if (s.slice(-5) === '/foaf') s = s.slice(0, -5) */
602+ if ( s . slice ( - 9 ) === '/foaf.rdf' ) s = s . slice ( 0 , - 9 )
603+ else if ( s . slice ( - 5 ) === '/foaf' ) s = s . slice ( 0 , - 5 )
619604
620605 // Eh? Why not do this? e.g. dc:title needs it only trim URIs, not rdfs:labels
621606 var slash = s . lastIndexOf ( '/' , s . length - 2 ) // (len-2) excludes trailing slash
0 commit comments